Fabian Peter Hammerle 10 سال پیش
والد
کامیت
87e127d575
5فایلهای تغییر یافته به همراه76 افزوده شده و 18 حذف شده
  1. 1 1
      Beat.h
  2. 13 1
      CMakeLists.txt
  3. 16 7
      Loop.h
  4. 33 9
      main.cpp
  5. 13 0
      sleep.h

+ 1 - 1
Beat.h

@@ -2,9 +2,9 @@
 
 class Beat
 {
+public:
     void trigger() 
     {
-        std::cout << "\atick" << std::endl;
     }
 };
 

+ 13 - 1
CMakeLists.txt

@@ -1,7 +1,19 @@
 cmake_minimum_required (VERSION 2.8.0)
 project (launchpad-sequencer)
+
 include_directories("${CMAKE_SOURCE_DIR}")
-add_definitions(-pthread)
+include_directories("${CMAKE_SOURCE_DIR}/rtmidi")
+
+link_directories("${CMAKE_SOURCE_DIR}/rtmidi/.libs")
+
 add_definitions(-std=c++11)
+add_definitions(-pthread)
+
+set(CMAKE_EXE_COMPILER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
+add_compile_options(-pthread)
+SET(CMAKE_EXE_LINKER_FLAGS "-pthread")
+
 add_executable(launchpad-sequencer main.cpp)
+target_link_libraries(launchpad-sequencer librtmidi.so) 

+ 16 - 7
Loop.h

@@ -21,9 +21,10 @@ public:
     std::vector<Bar> bars;
 
     Loop()
-        : bpm(60), stopNext(false), enabled(false), 
-          currentBarIndex(0), currentBeatIndex(0), lastBeatTime(0),
-          loopThread(&Loop::loop, this)
+        : loopThread(&Loop::loop, this),
+          bpm(60), stopNext(false), enabled(false), 
+          currentBarIndex(0), currentBeatIndex(0), 
+          lastBeatTime(0), bars(1)
     {
     }
 
@@ -76,15 +77,23 @@ private:
 
     void beat() 
     {
-        std::cout << "\a" << lastBeatTime.count() << std::endl;
+        // std::cout << "\a" << lastBeatTime.count() << std::endl;
         if(bars.size() > 0) {
             if(currentBarIndex >= bars.size()) {
                 currentBarIndex = 0;
             }
-        
-            std::cout << "trigger bar#" << currentBarIndex << std::endl;
+            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();
 
-            currentBarIndex++;
+            currentBeatIndex++;
         }
 
         lastBeatTime = getMillisecondsSinceEpoch();

+ 33 - 9
main.cpp

@@ -1,19 +1,43 @@
 #include <iostream>
+#include <vector>
 #include <Loop.h>
+#include "Launchpad.h"
+#include "sleep.h"
 
-int main() 
+class Sequencer
 {
-    Loop loop;
+    std::vector<Loop> loops;
+    unsigned int currentLoopIndex;
 
-    loop.bars.push_back(Bar());
-    loop.bars.push_back(Bar());
+public:
+    Sequencer();
     
-    loop.start();
+    void run();
+};
+
+class PlaybackScreen : public LaunchpadScreen
+{
+};
 
-    loop.setBpm(60);
-    std::this_thread::sleep_for(std::chrono::milliseconds(2000));
-    loop.setBpm(120);
-    std::this_thread::sleep_for(std::chrono::milliseconds(2000));
+Sequencer::Sequencer()
+    : loops(1), currentLoopIndex(0)
+{
+}
+
+void Sequencer::run()
+{
+    loops[0].start();
+
+    while(true) {
+        sleep(50);
+    }
+}
+
+Sequencer sequencer;
+
+int main() 
+{
+    sequencer.run();
 
     return 0;
 }

+ 13 - 0
sleep.h

@@ -0,0 +1,13 @@
+#ifndef sleep_h
+#define sleep_h
+
+// Platform-dependent sleep routines.
+#if defined(__WINDOWS_MM__)
+  #include <windows.h>
+  #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 
+#else // Unix variants
+  #include <unistd.h>
+  #define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
+#endif
+
+#endif