ConfigurationScreen.cpp 4.0 KB

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