Ver Fonte

config screen: bpm

Fabian Peter Hammerle há 10 anos atrás
pai
commit
b379c69eda
2 ficheiros alterados com 34 adições e 4 exclusões
  1. 32 4
      ConfigurationScreen.cpp
  2. 2 0
      colors.h

+ 32 - 4
ConfigurationScreen.cpp

@@ -22,6 +22,8 @@ void ConfigurationScreen::keyPressed(unsigned char x, unsigned char y)
                 break;
         }
     } else {
+        Player::Bpm minBpm = 1;
+        Player::Bpm maxBpm = (1 << (configWidth * 2)) - 1;
         switch(y) {
             case 0: { // number of beats
                 unsigned int bit = (1 << (configWidth - x - 1));
@@ -32,16 +34,30 @@ void ConfigurationScreen::keyPressed(unsigned char x, unsigned char y)
             case 1: { // sequence expansion
                 unsigned int factor = x + 2;
                 sequencer.beats.expand(factor);
-                sequencer.player.setBpm(sequencer.player.getBpm() * factor);
+                sequencer.player.setBpm(std::min(
+                    sequencer.player.getBpm() * factor,
+                    maxBpm
+                    ));
                 } break;
             case 2: { // sequence reduction erasing conflicts
                 unsigned int factor = x + 2;
                 sequencer.beats.reduceErasingConflicts(factor);
-                sequencer.player.setBpm(
-                    std::max(sequencer.player.getBpm() / factor,
-                    (Player::Bpm)1
+                sequencer.player.setBpm(std::max(
+                    sequencer.player.getBpm() / factor,
+                    minBpm
                     ));
                 } break;
+            case 4: // bpm
+            case 5: {
+                Player::Bpm bit = (1 << (configWidth - x - 1));
+                if(y == 5) {
+                    bit = (bit << configWidth);
+                }
+                Player::Bpm bpm = sequencer.player.getBpm() ^ bit;
+                if(bpm >= minBpm && bpm <= maxBpm) {
+                    sequencer.player.setBpm(bpm);
+                    std::cout << "set bpm to " << sequencer.player.getBpm() << std::endl;           }
+                } break;
         }
         // sequencer.beats.print(std::cout);
     }
@@ -79,6 +95,18 @@ void ConfigurationScreen::refresh(unsigned char x, unsigned char y)
             case 2: // reduce erasing conflicts
                setColor(x, y, colors::sequenceReductionErasingConflictsButton);
                break;
+            case 4: // bpm
+            case 5: {
+                Player::Bpm bit = (1 << (configWidth - x - 1));
+                if(y == 5) {
+                    bit = (bit << configWidth);
+                }
+                if(sequencer.player.getBpm() & bit) {
+                    setColor(x, y, colors::activeBpmCount);
+                } else {
+                    setColor(x, y, colors::inactiveBpmCount);
+                }
+                } break;
         }
     }
 }

+ 2 - 0
colors.h

@@ -22,5 +22,7 @@ Color inactiveBeatsCount(1, 0);
 Color activeBeatsCount(3, 1);
 Color sequenceExpansionButton(0, 1);
 Color sequenceReductionErasingConflictsButton(2, 0);
+Color inactiveBpmCount(0, 1);
+Color activeBpmCount(1, 3);
 
 }; // color