Sfoglia il codice sorgente

number of beats configuration

Fabian Peter Hammerle 10 anni fa
parent
commit
1f521c1d82
8 ha cambiato i file con 100 aggiunte e 4 eliminazioni
  1. 60 0
      ConfigurationScreen.cpp
  2. 23 0
      ConfigurationScreen.h
  3. 9 2
      PlaybackScreen.cpp
  4. 1 0
      PlaybackScreen.h
  5. 0 1
      Screen.h
  6. 2 1
      Sequencer.cpp
  7. 2 0
      Sequencer.h
  8. 3 0
      colors.h

+ 60 - 0
ConfigurationScreen.cpp

@@ -0,0 +1,60 @@
+#include "Sequencer.h"
+#include "ConfigurationScreen.h"
+#include "colors.h"
+#include <iostream>
+
+ConfigurationScreen::ConfigurationScreen(Sequencer& seq)
+    : parent(seq)
+{
+}
+
+void ConfigurationScreen::keyPressed(unsigned char x, unsigned char y)
+{
+    std::cout << "config clicked x=" << (int)x << ", y=" << (int)y << std::endl;
+
+    if(x == 8) { // very right
+    } else if(y == 8) { // very top
+        bool playing = sequencer.player.isPlaying();
+        switch(x) {
+            case 5:
+                disable();
+                sequencer.playbackScreen.enable();
+                break;
+        }
+    } else {
+        if(y == 0) { // bpm
+            unsigned int bit = (1 << (configWidth - x - 1));
+            unsigned int beatsCount = sequencer.beats.size() ^ bit;
+            std::cout << "set number of beats to " << beatsCount << std::endl;
+            sequencer.beats.resize(beatsCount);
+        }
+    }
+
+    refreshAll();
+}
+
+void ConfigurationScreen::keyReleased(unsigned char x, unsigned char y)
+{
+    refreshAll();
+}
+
+void ConfigurationScreen::refresh(unsigned char x, unsigned char y)
+{
+    if(x == 8) { // very right
+    } else if(y == 8) { // very top
+        switch(x) {
+            case 5:
+                setColor(x, y, colors::activeOption);
+                break;
+        }
+    } else {
+        if(y == 0) { // bpm
+            unsigned int beatsCount = sequencer.beats.size();
+            if(beatsCount & (1 << (configWidth - x - 1))) {
+                setColor(x, y, colors::activeBeatsCount);
+            } else {
+                setColor(x, y, colors::inactiveBeatsCount);
+            }
+        }
+    }
+}

+ 23 - 0
ConfigurationScreen.h

@@ -0,0 +1,23 @@
+#pragma once
+#include "Screen.h"
+#include "Sequencer.h"
+#include "Player.h"
+
+class ConfigurationScreen : public Screen
+{
+    typedef Screen parent;
+
+public:
+
+    midi::Launchpad::KeyCoordinate configWidth = midi::Launchpad::width - 1;
+
+    ConfigurationScreen(Sequencer& seq);
+    
+protected:
+
+	virtual void keyPressed(unsigned char x, unsigned char y);
+	virtual void keyReleased(unsigned char x, unsigned char y);
+
+    virtual void refresh(unsigned char x, unsigned char y);
+
+};

+ 9 - 2
PlaybackScreen.cpp

@@ -52,10 +52,14 @@ void PlaybackScreen::keyPressed(unsigned char x, unsigned char y)
                 }
                 break;
             case 3: // right
-                if(!playing && beatDisplayOffset < (sequencer.beats.size() / beatDisplayWidth)) {
+                if(!playing && (beatDisplayOffset + beatDisplayWidth) < sequencer.beats.size()) {
                     beatDisplayOffset += beatDisplayWidth;
                 }
                 break;
+            case 5: 
+                disable();
+                sequencer.configScreen.enable();
+                break;
             case 7: // start / stop
                 if(playing) {
                     sequencer.player.stop();
@@ -114,12 +118,15 @@ void PlaybackScreen::refresh(unsigned char x, unsigned char y)
                 }
                 break;
             case 3: // right
-                if(!playing && beatDisplayOffset < (sequencer.beats.size() / beatDisplayWidth)) {
+                if(!playing && (beatDisplayOffset + beatDisplayWidth) < sequencer.beats.size()) {
                     setColor(x, y, colors::inactiveOption);
                 } else {
                     setColor(x, y, colors::dark);
                 }
                 break;
+            case 5: 
+                setColor(x, y, colors::inactiveOption);
+                break;
             case 7: // start / stop
                 if(playing) {
                     setColor(x, y, colors::activeOption);

+ 1 - 0
PlaybackScreen.h

@@ -1,5 +1,6 @@
 #pragma once
 #include "Screen.h"
+#include "Sequencer.h"
 #include "Player.h"
 
 class PlaybackScreen : public Screen

+ 0 - 1
Screen.h

@@ -1,6 +1,5 @@
 #pragma once
 #include "midi/LaunchpadScreen.h"
-#include "Sequencer.h"
 
 class Sequencer;
 

+ 2 - 1
Sequencer.cpp

@@ -2,10 +2,11 @@
 #include <iostream>
 
 Sequencer::Sequencer()
-    : launchpad(), playbackScreen(*this), messages(),
+    : launchpad(), playbackScreen(*this), configScreen(*this), messages(),
       defaultOutputChannel(9), player(&midiOut, &beats, *this)
 {
     playbackScreen.setLaunchpad(launchpad);
+    configScreen.setLaunchpad(launchpad);
     beats.resize(midi::Launchpad::width - 1);
 }
 

+ 2 - 0
Sequencer.h

@@ -5,6 +5,7 @@
 #include "midi/Message.h"
 #include "midi/BeatSequence.h"
 #include "PlaybackScreen.h"
+#include "ConfigurationScreen.h"
 #include "Player.h"
 
 class Sequencer
@@ -12,6 +13,7 @@ class Sequencer
 public:
     midi::Launchpad launchpad;
     PlaybackScreen playbackScreen;
+    ConfigurationScreen configScreen;
     std::vector<std::shared_ptr<midi::Message>> messages;
     unsigned char defaultOutputChannel;
     midi::Output midiOut;

+ 3 - 0
colors.h

@@ -12,4 +12,7 @@ Color activeMessage(3, 2);
 Color activeOption(3, 3);
 Color inactiveOption(1, 2);
 
+Color inactiveBeatsCount(0, 1);
+Color activeBeatsCount(1, 3);
+
 }; // color