ConfigurationScreen.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "Sequencer.h"
  2. #include "ConfigurationScreen.h"
  3. #include "colors.h"
  4. #include <iostream>
  5. ConfigurationScreen::ConfigurationScreen(Sequencer& seq)
  6. : parent(seq)
  7. {
  8. }
  9. void ConfigurationScreen::keyPressed(unsigned char x, unsigned char y)
  10. {
  11. std::cout << "config clicked x=" << (int)x << ", y=" << (int)y << std::endl;
  12. if(x == 8) { // very right
  13. } else if(y == 8) { // very top
  14. bool playing = sequencer.player.isPlaying();
  15. switch(x) {
  16. case 5:
  17. disable();
  18. sequencer.playbackScreen.enable();
  19. break;
  20. }
  21. } else {
  22. Player::Bpm minBpm = 1;
  23. Player::Bpm maxBpm = (1 << (configWidth * 2)) - 1;
  24. BeatIndex maxBeatsCount = (1 << configWidth) - 1;
  25. switch(y) {
  26. case 0: { // number of beats
  27. unsigned int bit = (1 << (configWidth - x - 1));
  28. unsigned int beatsCount = sequencer.beats.size() ^ bit;
  29. std::cout << "set number of beats to " << beatsCount << std::endl;
  30. sequencer.beats.resize(beatsCount);
  31. } break;
  32. case 1: { // sequence expansion
  33. unsigned int factor = x + 2;
  34. if(sequencer.beats.size() * factor <= maxBeatsCount) {
  35. sequencer.beats.expand(factor);
  36. sequencer.player.setBpm(std::min(
  37. sequencer.player.getBpm() * factor,
  38. maxBpm
  39. ));
  40. }
  41. } break;
  42. case 2: { // sequence reduction erasing conflicts
  43. unsigned int factor = x + 2;
  44. sequencer.beats.reduceErasingConflicts(factor);
  45. sequencer.player.setBpm(std::max(
  46. sequencer.player.getBpm() / factor,
  47. minBpm
  48. ));
  49. } break;
  50. case 4: // bpm
  51. case 5: {
  52. Player::Bpm bit = (1 << (configWidth - x - 1));
  53. if(y == 5) {
  54. bit = (bit << configWidth);
  55. }
  56. Player::Bpm bpm = sequencer.player.getBpm() ^ bit;
  57. if(bpm >= minBpm && bpm <= maxBpm) {
  58. sequencer.player.setBpm(bpm);
  59. std::cout << "set bpm to " << sequencer.player.getBpm() << std::endl; }
  60. } break;
  61. }
  62. // sequencer.beats.print(std::cout);
  63. }
  64. refreshAll();
  65. }
  66. void ConfigurationScreen::keyReleased(unsigned char x, unsigned char y)
  67. {
  68. refreshAll();
  69. }
  70. void ConfigurationScreen::refresh(unsigned char x, unsigned char y)
  71. {
  72. if(x == 8) { // very right
  73. } else if(y == 8) { // very top
  74. switch(x) {
  75. case 5:
  76. setColor(x, y, colors::activeOption);
  77. break;
  78. }
  79. } else {
  80. switch(y) {
  81. case 0: { // number of beats
  82. unsigned int beatsCount = sequencer.beats.size();
  83. if(beatsCount & (1 << (configWidth - x - 1))) {
  84. setColor(x, y, colors::activeBeatsCount);
  85. } else {
  86. setColor(x, y, colors::inactiveBeatsCount);
  87. }
  88. } break;
  89. case 1: // sequence expansion
  90. setColor(x, y, colors::sequenceExpansionButton);
  91. break;
  92. case 2: // reduce erasing conflicts
  93. setColor(x, y, colors::sequenceReductionErasingConflictsButton);
  94. break;
  95. case 4: // bpm
  96. case 5: {
  97. Player::Bpm bit = (1 << (configWidth - x - 1));
  98. if(y == 5) {
  99. bit = (bit << configWidth);
  100. }
  101. if(sequencer.player.getBpm() & bit) {
  102. setColor(x, y, colors::activeBpmCount);
  103. } else {
  104. setColor(x, y, colors::inactiveBpmCount);
  105. }
  106. } break;
  107. }
  108. }
  109. }