Kaynağa Gözat

introduced beat diplay offset

Fabian Peter Hammerle 10 yıl önce
ebeveyn
işleme
9537384f26
4 değiştirilmiş dosya ile 65 ekleme ve 23 silme
  1. 57 22
      PlaybackScreen.cpp
  2. 5 0
      PlaybackScreen.h
  3. 2 0
      Sequencer.cpp
  4. 1 1
      midi

+ 57 - 22
PlaybackScreen.cpp

@@ -5,12 +5,20 @@
 
 
 PlaybackScreen::PlaybackScreen(Sequencer& seq)
-    : sequencer(seq)
+    : beatDisplayOffset(0), sequencer(seq)
 {
 }
 
 void PlaybackScreen::enable()
 {
+    if(sequencer.beats.size() == 0) {
+        beatDisplayOffset = 0;
+    } else {
+        beatDisplayOffset = std::min(
+            beatDisplayOffset, 
+            (Player::BeatIndex)(sequencer.beats.size() - 1) / beatDisplayWidth * beatDisplayWidth
+            );
+    }
     refreshAll();
     parent::enable();
 }
@@ -18,10 +26,8 @@ void PlaybackScreen::enable()
 void PlaybackScreen::beforeBeat(Player::BeatIndex beat)
 {
     std::cout << "before beat #" << beat << std::endl;
-    for(unsigned char y = 0; y < midi::Launchpad::height - 1; y++) {
-        refresh(beat, y);
-        refresh((beat - 1) % (midi::Launchpad::width - 1), y);
-    }
+    beatDisplayOffset = beat / beatDisplayWidth * beatDisplayWidth;
+    refreshAll();
 }
 
 void PlaybackScreen::afterBeat(Player::BeatIndex beat)
@@ -39,15 +45,28 @@ void PlaybackScreen::keyPressed(unsigned char x, unsigned char y)
             sequencer.midiOut.sendMessage(*msg_ptr);
         }
     } else if(y == 8) { // very top
-        if(x == 0) {
-            if(sequencer.player.isPlaying()) {
-                sequencer.player.stop();
-            } else {
-                sequencer.player.loop();
-            }
+        bool playing = sequencer.player.isPlaying();
+        switch(x) {
+            case 2: // left
+                if(!playing && beatDisplayOffset > 0) {
+                    beatDisplayOffset = std::max((Player::BeatIndex)0, beatDisplayOffset - beatDisplayWidth);
+                }
+                break;
+            case 3: // right
+                if(!playing && beatDisplayOffset < (sequencer.beats.size() / beatDisplayWidth)) {
+                    beatDisplayOffset += beatDisplayWidth;
+                }
+                break;
+            case 7: // start / stop
+                if(playing) {
+                    sequencer.player.stop();
+                } else {
+                    sequencer.player.loop();
+                }
+                break;
         }
     } else {
-        Player::BeatIndex beatIndex = x;
+        Player::BeatIndex beatIndex = x + beatDisplayOffset;
         if(beatIndex < sequencer.beats.size() && y < sequencer.messages.size()) {
             midi::MessageList& beat = sequencer.beats[beatIndex];
             std::cout << "before ";
@@ -69,12 +88,12 @@ void PlaybackScreen::keyPressed(unsigned char x, unsigned char y)
         }
     }
 
-    refresh(x, y);
+    refreshAll();
 }
 
 void PlaybackScreen::keyReleased(unsigned char x, unsigned char y)
 {
-    refresh(x, y);
+    refreshAll();
 }
 
 void PlaybackScreen::refresh(unsigned char x, unsigned char y)
@@ -86,16 +105,32 @@ void PlaybackScreen::refresh(unsigned char x, unsigned char y)
             setColor(x, y, colors::dark);
         }
     } else if(y == 8) { // very top
-        if(x == 0) {
-            // start / stop
-            if(sequencer.player.isPlaying()) {
-                setColor(x, y, colors::activeOption);
-            } else {
-                setColor(x, y, colors::inactiveOption);
-            }
+        bool playing = sequencer.player.isPlaying();
+        switch(x) {
+            case 2: // left
+                if(!playing && beatDisplayOffset > 0) {
+                    setColor(x, y, colors::inactiveOption);
+                } else {
+                    setColor(x, y, colors::dark);
+                }
+                break;
+            case 3: // right
+                if(!playing && beatDisplayOffset < (sequencer.beats.size() / beatDisplayWidth)) {
+                    setColor(x, y, colors::inactiveOption);
+                } else {
+                    setColor(x, y, colors::dark);
+                }
+                break;
+            case 7: // start / stop
+                if(playing) {
+                    setColor(x, y, colors::activeOption);
+                } else {
+                    setColor(x, y, colors::inactiveOption);
+                }
+                break;
         }
     } else {
-        Player::BeatIndex beatIndex = x;
+        Player::BeatIndex beatIndex = x + beatDisplayOffset;
         if(beatIndex < sequencer.beats.size() && y < sequencer.messages.size()) {
             midi::MessageList& beat = sequencer.beats[beatIndex];
             std::shared_ptr<midi::Message> msg_ptr = sequencer.messages[y];

+ 5 - 0
PlaybackScreen.h

@@ -9,8 +9,12 @@ class PlaybackScreen : public midi::LaunchpadScreen
 {
     typedef midi::LaunchpadScreen parent;
 
+    Player::BeatIndex beatDisplayOffset;
+
 public:
 
+    midi::Launchpad::KeyCoordinate beatDisplayWidth = midi::Launchpad::width - 1;
+
     Sequencer& sequencer;
 
     PlaybackScreen(Sequencer& seq);
@@ -27,5 +31,6 @@ protected:
 
     void refresh(unsigned char x, unsigned char y);
     void refreshAll();
+
 };
 	

+ 2 - 0
Sequencer.cpp

@@ -20,6 +20,8 @@ void Sequencer::run()
         messages[i] = std::make_shared<midi::NoteOnMessage>(defaultOutputChannel, 36 + i, 100 + i);
     }
 
+    beats.resize(4 * 3);
+
     playbackScreen.enable();
 
     player.setBpm(320);

+ 1 - 1
midi

@@ -1 +1 @@
-Subproject commit 8b46a7690197d1dc7fd403c245aa439cbf203fb4
+Subproject commit affb35bea9180b5fac0792582daf51399dbf3f0c