ConfigurationScreen.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. sequencer.beats.expand(factor);
  32. sequencer.player.setBpm(sequencer.player.getBpm() * factor);
  33. } break;
  34. }
  35. }
  36. refreshAll();
  37. }
  38. void ConfigurationScreen::keyReleased(unsigned char x, unsigned char y)
  39. {
  40. refreshAll();
  41. }
  42. void ConfigurationScreen::refresh(unsigned char x, unsigned char y)
  43. {
  44. if(x == 8) { // very right
  45. } else if(y == 8) { // very top
  46. switch(x) {
  47. case 5:
  48. setColor(x, y, colors::activeOption);
  49. break;
  50. }
  51. } else {
  52. switch(y) {
  53. case 0: { // number of beats
  54. unsigned int beatsCount = sequencer.beats.size();
  55. if(beatsCount & (1 << (configWidth - x - 1))) {
  56. setColor(x, y, colors::activeBeatsCount);
  57. } else {
  58. setColor(x, y, colors::inactiveBeatsCount);
  59. }
  60. } break;
  61. case 1: // sequence expansion
  62. setColor(x, y, colors::sequenceExpansionButton);
  63. break;
  64. }
  65. }
  66. }