Prechádzať zdrojové kódy

moved message insertion to toogleOnMessage()

Fabian Peter Hammerle 10 rokov pred
rodič
commit
46405646e9
4 zmenil súbory, kde vykonal 27 pridanie a 15 odobranie
  1. 2 2
      BeatSequence.cpp
  2. 2 2
      BeatSequence.h
  3. 20 11
      PlaybackScreen.cpp
  4. 3 0
      PlaybackScreen.h

+ 2 - 2
BeatSequence.cpp

@@ -61,13 +61,13 @@ void BeatSequence::resize(BeatIndex size)
     refreshRegistry();
 }
 
-void BeatSequence::pushFrontMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message>& msg_ptr)
+void BeatSequence::pushFrontMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr)
 {
     parent::at(beatIndex).push_front(msg_ptr);
     registerMessage(beatIndex, msg_ptr);
 }
 
-void BeatSequence::pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message>& msg_ptr)
+void BeatSequence::pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr)
 {
     parent::at(beatIndex).push_back(msg_ptr);
     registerMessage(beatIndex, msg_ptr);

+ 2 - 2
BeatSequence.h

@@ -31,8 +31,8 @@ public:
     const midi::MessageList& at(BeatIndex beatIndex) const;
     const midi::MessageList& operator[](BeatIndex beatIndex) const;
     void resize(BeatIndex size);
-    void pushFrontMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message>& msg_ptr);
-    void pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message>& msg_ptr);
+    void pushFrontMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr);
+    void pushBackMessage(BeatIndex beatIndex, std::shared_ptr<midi::Message> msg_ptr);
     void eraseMessage(BeatIndex beatIndex, midi::MessageList::const_iterator msg_it);
     void expand(BeatIndex factor);
     void reduceToNeighbour(BeatIndex factor);

+ 20 - 11
PlaybackScreen.cpp

@@ -71,18 +71,11 @@ void PlaybackScreen::keyPressed(unsigned char x, unsigned char y)
     } else {
         Player::BeatIndex beatIndex = x + beatDisplayOffset;
         if(beatIndex < sequencer.beats.size() && y < sequencer.messages.size()) {
-            const midi::MessageList& beat = sequencer.beats[beatIndex];
-            std::shared_ptr<midi::Message> msg_ptr = sequencer.messages[y];
-            // msg_ptr->print(std::cout);
-            midi::MessageList::const_iterator beat_msg_it = beat.find(*msg_ptr);
-            if(beat_msg_it == beat.end()) {
-                // insert message at beat
-                sequencer.beats.pushBackMessage(beatIndex, msg_ptr);
-            } else {
-                // remove message from beat
-                sequencer.beats.eraseMessage(beatIndex, beat_msg_it);
+            std::shared_ptr<midi::NoteOnMessage> noteOnMessage_ptr
+                = std::dynamic_pointer_cast<midi::NoteOnMessage>(sequencer.messages[y]);
+            if(noteOnMessage_ptr) {
+                toggleOnMessage(noteOnMessage_ptr, beatIndex);
             }
-            sequencer.beats.printRegistry(std::cout);
         }
     }
 
@@ -149,3 +142,19 @@ void PlaybackScreen::refresh(unsigned char x, unsigned char y)
         }
     }
 }
+    
+void PlaybackScreen::toggleOnMessage(std::shared_ptr<midi::NoteOnMessage> noteOnMessage_ptr, Player::BeatIndex beatIndex)
+{
+    noteOnMessage_ptr->print(std::cout);
+
+    const midi::MessageList& beat = sequencer.beats[beatIndex];
+    midi::MessageList::const_iterator beat_msg_it = beat.find(*noteOnMessage_ptr);
+    if(beat_msg_it == beat.end()) {
+        // insert message at beat
+        sequencer.beats.pushBackMessage(beatIndex, std::dynamic_pointer_cast<midi::Message>(noteOnMessage_ptr));
+    } else {
+        // remove message from beat
+        sequencer.beats.eraseMessage(beatIndex, beat_msg_it);
+    }
+    sequencer.beats.printRegistry(std::cout);
+}

+ 3 - 0
PlaybackScreen.h

@@ -27,5 +27,8 @@ protected:
 
     virtual void refresh(unsigned char x, unsigned char y);
 
+private:
+
+    void toggleOnMessage(std::shared_ptr<midi::NoteOnMessage> noteOnMessage_ptr, Player::BeatIndex beatIndex);
 };