aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-02-10 04:54:15 +0000
committerDavid Robillard <d@drobilla.net>2007-02-10 04:54:15 +0000
commit87c0a475bd76ca33883eeafc2a86bc89a84eec2f (patch)
treef33b2a91e312d46ccd095065e62043a6e5d7a687 /src
parentb924ead0db7c09ee50d2d4eee487b844c5fb867b (diff)
downloadmachina-87c0a475bd76ca33883eeafc2a86bc89a84eec2f.tar.gz
machina-87c0a475bd76ca33883eeafc2a86bc89a84eec2f.tar.bz2
machina-87c0a475bd76ca33883eeafc2a86bc89a84eec2f.zip
Reorganization to make MIDI generic and abstract away driver functionality
(so actions are serializable and usable with many drivers). Partial commit, broken. git-svn-id: http://svn.drobilla.net/lad/machina@298 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/engine/JackActions.cpp88
-rw-r--r--src/engine/Makefile.am2
-rw-r--r--src/engine/MidiActions.cpp60
-rw-r--r--src/engine/machina/JackDriver.hpp25
-rw-r--r--src/engine/machina/Makefile.am5
-rw-r--r--src/engine/machina/MidiAction.hpp (renamed from src/engine/machina/JackActions.hpp)32
-rw-r--r--src/engine/machina/types.hpp1
7 files changed, 91 insertions, 122 deletions
diff --git a/src/engine/JackActions.cpp b/src/engine/JackActions.cpp
deleted file mode 100644
index b55e493..0000000
--- a/src/engine/JackActions.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/* This file is part of Machina.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Machina is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <iostream>
-#include "machina/JackActions.hpp"
-#include "machina/JackDriver.hpp"
-
-namespace Machina {
-
-
-/* NOTE ON */
-
-JackNoteOnAction::JackNoteOnAction(WeakPtr<JackDriver> driver,
- unsigned char note_num)
- : _driver(driver)
- , _note_num(note_num)
-{
-}
-
-
-void
-JackNoteOnAction::execute(Timestamp time)
-{
- SharedPtr<JackDriver> driver = _driver.lock();
- if (!driver)
- return;
-
- const FrameCount nframes = driver->current_cycle_nframes();
- const FrameCount offset = driver->stamp_to_offset(time);
-
- //std::cerr << offset << " \tNOTE ON:\t" << (int)_note_num << "\t@ " << time << std::endl;
-
- jack_midi_data_t ev[] = { 0x80, _note_num, 0x40 };
-
- jack_midi_event_write(
- jack_port_get_buffer(driver->output_port(), nframes),
- offset, ev, 3, nframes);
-}
-
-
-
-/* NOTE OFF */
-
-JackNoteOffAction::JackNoteOffAction(WeakPtr<JackDriver> driver,
- unsigned char note_num)
- : _driver(driver)
- , _note_num(note_num)
-{
-}
-
-
-void
-JackNoteOffAction::execute(Timestamp time)
-{
- SharedPtr<JackDriver> driver = _driver.lock();
- if (!driver)
- return;
-
- const FrameCount nframes = driver->current_cycle_nframes();
- const FrameCount offset = driver->stamp_to_offset(time);
-
- //std::cerr << offset << " \tNOTE OFF:\t" << (int)_note_num << "\t@ " << time << std::endl;
-
- jack_midi_data_t ev[] = { 0x90, _note_num, 0x40 };
-
- jack_midi_event_write(
- jack_port_get_buffer(driver->output_port(), nframes),
- offset, ev, 3, nframes);
-}
-
-
-} // namespace Machina
-
-
diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am
index 2e0c363..b8f248c 100644
--- a/src/engine/Makefile.am
+++ b/src/engine/Makefile.am
@@ -11,7 +11,7 @@ libmachina_la_SOURCES = \
Machine.cpp \
Loader.h \
Loader.cpp \
+ MidiActions.cpp \
JackDriver.h \
JackDriver.cpp \
- JackActions.cpp \
JackNodeFactory.cpp
diff --git a/src/engine/MidiActions.cpp b/src/engine/MidiActions.cpp
new file mode 100644
index 0000000..8d07c3a
--- /dev/null
+++ b/src/engine/MidiActions.cpp
@@ -0,0 +1,60 @@
+/* This file is part of Machina.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Machina is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <iostream>
+#include "machina/MidiAction.hpp"
+#include "machina/MidiDriver.hpp"
+
+namespace Machina {
+
+
+/* NOTE ON */
+
+MidiAction(WeakPtr<JackDriver> driver,
+ size_t size,
+ unsigned char* event)
+ : _driver(driver)
+ , _size(size)
+ , _event(event)
+{
+}
+
+
+void
+MidiAction::execute(Timestamp time)
+{
+ SharedPtr<MidiDriver> driver = _driver.lock();
+ if (!driver)
+ return;
+
+ const FrameCount nframes = driver->current_cycle_nframes();
+ const FrameCount offset = driver->stamp_to_offset(time);
+
+ //std::cerr << offset << " \tMIDI @ " << time << std::endl;
+
+ //jack_midi_data_t ev[] = { 0x80, _note_num, 0x40 }; note on
+ //jack_midi_data_t ev[] = { 0x90, _note_num, 0x40 }; note off
+
+ jack_midi_event_write(
+ jack_port_get_buffer(driver->output_port(), nframes),
+ offset, ev, _size, _event);
+}
+
+
+} // namespace Machina
+
+
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
index 84c9223..bae3ab2 100644
--- a/src/engine/machina/JackDriver.hpp
+++ b/src/engine/machina/JackDriver.hpp
@@ -22,11 +22,17 @@
#include <raul/SharedPtr.h>
#include <jack/midiport.h>
#include "Machine.hpp"
+#include "MidiDriver.hpp"
namespace Machina {
-class JackDriver : public Raul::JackDriver {
+/** Realtime JACK Driver.
+ *
+ * "Ticks" are individual frames when running under this driver, and all code
+ * in the processing context must be realtime safe (non-blocking).
+ */
+class JackDriver : public Raul::JackDriver, public Machina::MidiDriver {
public:
JackDriver();
@@ -36,18 +42,17 @@ public:
void set_machine(SharedPtr<Machine> machine) { _machine = machine; }
// Audio context
- Timestamp stamp_to_offset(Timestamp stamp);
- jack_port_t* output_port() { return _output_port; }
- //Timestamp current_cycle_start() { return _current_cycle_start; }
- //Timestamp current_cycle_offset() { return _current_cycle_offset; }
- FrameCount current_cycle_nframes() { return _current_cycle_nframes; }
+ Timestamp cycle_start() { return _current_cycle_start; }
+ FrameCount cycle_length() { return _current_cycle_nframes; }
-
-protected:
- virtual void on_process(jack_nframes_t nframes);
-
private:
+ // Audio context
+ Timestamp subcycle_offset() { return _current_cycle_offset; }
+ jack_port_t* output_port() { return _output_port; }
+ virtual void on_process(jack_nframes_t nframes);
+ Timestamp stamp_to_offset(Timestamp stamp);
SharedPtr<Machine> _machine;
+
jack_port_t* _output_port;
Timestamp _current_cycle_start;
Timestamp _current_cycle_offset; ///< for split cycles
diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am
index eca6f9b..ffcae1e 100644
--- a/src/engine/machina/Makefile.am
+++ b/src/engine/machina/Makefile.am
@@ -7,6 +7,7 @@ libmachinainclude_HEADERS = \
Machine.hpp \
Loader.hpp \
JackDriver.hpp \
- JackActions.hpp \
NodeFactory.hpp \
- JackNodeFactory.hpp
+ JackNodeFactory.hpp \
+ MidiAction.hpp \
+ MidiDriver.hpp
diff --git a/src/engine/machina/JackActions.hpp b/src/engine/machina/MidiAction.hpp
index 0eb50b8..2e1d1fc 100644
--- a/src/engine/machina/JackActions.hpp
+++ b/src/engine/machina/MidiAction.hpp
@@ -15,8 +15,8 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef MACHINA_JACKACTIONS_HPP
-#define MACHINA_JACKACTIONS_HPP
+#ifndef MACHINA_MIDIACTION_HPP
+#define MACHINA_MIDIACTION_HPP
#include <raul/WeakPtr.h>
#include "types.hpp"
@@ -24,34 +24,24 @@
namespace Machina {
-class Node;
-class JackDriver;
+class MidiDriver;
-class JackNoteOnAction : public Action {
+class MidiAction : public Action {
public:
- JackNoteOnAction(WeakPtr<JackDriver> driver, unsigned char note_num);
+ JackNoteOnAction(WeakPtr<MidiDriver> driver,
+ size_t size,
+ unsigned char* event);
void execute(Timestamp time);
private:
- WeakPtr<JackDriver> _driver;
- unsigned char _note_num;
-};
-
-
-class JackNoteOffAction : public Action {
-public:
- JackNoteOffAction(WeakPtr<JackDriver> driver, unsigned char note_num);
-
- void execute(Timestamp time);
-
-private:
- WeakPtr<JackDriver> _driver;
- unsigned char _note_num;
+ WeakPtr<MidiDriver> _driver;
+ size_t _size;
+ unsigned char* _event;
};
} // namespace Machina
-#endif // MACHINA_JACKACTIONS_HPP
+#endif // MACHINA_MIDIACTION_HPP
diff --git a/src/engine/machina/types.hpp b/src/engine/machina/types.hpp
index 8793fb1..db36901 100644
--- a/src/engine/machina/types.hpp
+++ b/src/engine/machina/types.hpp
@@ -26,6 +26,7 @@ namespace Machina {
typedef jack_nframes_t FrameCount;
typedef jack_nframes_t Timestamp;
+
} // namespace Machina
#endif // MACHINA_TYPES_HPP