Fabian Peter Hammerle 10 лет назад
Родитель
Сommit
d5ee5f890c
8 измененных файлов с 24 добавлено и 149 удалено
  1. 0 9
      Bar.h
  2. 0 10
      Beat.h
  3. 6 4
      CMakeLists.txt
  4. 0 111
      Loop.h
  5. 6 0
      PlaybackScreen.h
  6. 9 10
      Sequencer.h
  7. 2 5
      main.cpp
  8. 1 0
      midi

+ 0 - 9
Bar.h

@@ -1,9 +0,0 @@
-#include "Beat.h"
-
-class Bar
-{
-public:
-    static const unsigned short beatsCount = 8;
-    Beat beats[beatsCount];
-};
-

+ 0 - 10
Beat.h

@@ -1,10 +0,0 @@
-#include <iostream>
-
-class Beat
-{
-public:
-    void trigger() 
-    {
-    }
-};
-

+ 6 - 4
CMakeLists.txt

@@ -2,11 +2,13 @@ cmake_minimum_required (VERSION 2.8.0)
 project (launchpad-sequencer)
 
 include_directories("${CMAKE_SOURCE_DIR}")
-include_directories("${CMAKE_SOURCE_DIR}/rtmidi")
+link_directories("${CMAKE_SOURCE_DIR}/midi/lib")
+
+file(GLOB srcfiles *.cpp)
 
-link_directories("${CMAKE_SOURCE_DIR}/rtmidi/.libs")
 add_definitions(-pthread)
 add_definitions(-std=c++11)
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
-add_executable(launchpad-sequencer main.cpp)
-target_link_libraries(launchpad-sequencer librtmidi.so) 
+
+add_executable(launchpad-sequencer ${srcfiles})
+target_link_libraries(launchpad-sequencer midi) 

+ 0 - 111
Loop.h

@@ -1,111 +0,0 @@
-#include <iostream>
-#include <thread>
-#include <mutex>
-#include <chrono>
-#include <vector>
-#include "Bar.h"
-
-class Loop
-{
-    std::thread loopThread;
-    std::chrono::milliseconds lastBeatTime; 
-    unsigned short bpm;
-    std::mutex bpmLock;
-    bool stopNext;
-
-public:
-
-    bool enabled;
-    unsigned short currentBarIndex;
-    unsigned short currentBeatIndex;
-    std::vector<Bar> bars;
-
-    Loop()
-        : loopThread(&Loop::loop, this),
-          bpm(60), stopNext(false), enabled(false), 
-          currentBarIndex(0), currentBeatIndex(0), 
-          lastBeatTime(0), bars(1)
-    {
-    }
-
-    ~Loop()
-    {
-        stopNext = true;
-        loopThread.join();
-    }
-
-    void setBpm(unsigned short b)
-    {
-        bpmLock.lock();
-        bpm = b;
-        bpmLock.unlock();
-    }
-
-    unsigned short getBpm()
-    {
-        bpmLock.lock();
-        unsigned short r = bpm;
-        bpmLock.unlock();
-        return r;
-    }
-
-    std::chrono::milliseconds getBeatDuration()
-    {
-        return std::chrono::milliseconds(
-                (long long)((double)60 * 1000 / bpm)
-                );
-    }
-
-    void start()
-    {
-        enabled = true;
-    }
-
-    void stop()
-    {
-        enabled = false;
-    }
-
-private:
-
-    std::chrono::milliseconds getMillisecondsSinceEpoch()
-    {
-        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
-        std::chrono::system_clock::duration duration = now.time_since_epoch();
-        return std::chrono::duration_cast<std::chrono::milliseconds>(duration);
-    }
-
-    void beat() 
-    {
-        // std::cout << "\a" << lastBeatTime.count() << std::endl;
-        if(bars.size() > 0) {
-            if(currentBarIndex >= bars.size()) {
-                currentBarIndex = 0;
-            }
-            if(currentBeatIndex >= bars[currentBarIndex].beatsCount) {
-                currentBeatIndex = 0;
-                currentBarIndex++;
-                if(currentBarIndex >= bars.size()) {
-                    currentBarIndex = 0;
-                }
-            }
-
-            std::cout << "trigger bar#" << currentBarIndex << " beat#" << currentBeatIndex << std::endl;
-            bars[currentBarIndex].beats[currentBeatIndex].trigger();
-
-            currentBeatIndex++;
-        }
-
-        lastBeatTime = getMillisecondsSinceEpoch();
-    }
-
-    void loop()
-    {
-        while(!stopNext) {
-            if(enabled && (getMillisecondsSinceEpoch() - lastBeatTime) >= getBeatDuration()) {
-                beat();
-            }
-        }
-    }
-};
-

+ 6 - 0
PlaybackScreen.h

@@ -0,0 +1,6 @@
+#pragma once
+#include "midi/LaunchpadScreen.h"
+
+class PlaybackScreen : public midi::LaunchpadScreen
+{
+};

+ 9 - 10
Sequencer.h

@@ -1,26 +1,25 @@
+#pragma once
 #include <vector>
+#include <iostream>
+#include "midi/Launchpad.h"
+#include "PlaybackScreen.h"
 
 class Sequencer
 {
-    std::vector<Loop> loops;
-    unsigned int currentLoopIndex;
-
 public:
+    midi::Launchpad launchpad;
+
     Sequencer();
-    
     void run();
 };
 
 Sequencer::Sequencer()
-    : loops(1), currentLoopIndex(0)
+    : launchpad()
 {
 }
 
 void Sequencer::run()
 {
-    loops[0].start();
-
-    while(true) {
-        std::this_thread::sleep_for(std::chrono::milliseconds(50));
-    }
+    std::cout << __func__ << std::endl;
+    std::cin.ignore();
 }

+ 2 - 5
main.cpp

@@ -1,11 +1,8 @@
-#include <iostream>
-#include <Loop.h>
-#include <Sequencer.h>
-
-Sequencer sequencer;
+#include "Sequencer.h"
 
 int main() 
 {
+    Sequencer sequencer;
     sequencer.run();
 
     return 0;

+ 1 - 0
midi

@@ -0,0 +1 @@
+Subproject commit 8d32b041f56d23e428756482c46f07fb13997aa1