From 87c0a475bd76ca33883eeafc2a86bc89a84eec2f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 10 Feb 2007 04:54:15 +0000 Subject: 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 --- src/engine/JackActions.cpp | 88 -------------------------------------- src/engine/Makefile.am | 2 +- src/engine/MidiActions.cpp | 60 ++++++++++++++++++++++++++ src/engine/machina/JackActions.hpp | 57 ------------------------ src/engine/machina/JackDriver.hpp | 25 ++++++----- src/engine/machina/Makefile.am | 5 ++- src/engine/machina/MidiAction.hpp | 47 ++++++++++++++++++++ src/engine/machina/types.hpp | 1 + 8 files changed, 127 insertions(+), 158 deletions(-) delete mode 100644 src/engine/JackActions.cpp create mode 100644 src/engine/MidiActions.cpp delete mode 100644 src/engine/machina/JackActions.hpp create mode 100644 src/engine/machina/MidiAction.hpp 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 - * - * 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 -#include "machina/JackActions.hpp" -#include "machina/JackDriver.hpp" - -namespace Machina { - - -/* NOTE ON */ - -JackNoteOnAction::JackNoteOnAction(WeakPtr driver, - unsigned char note_num) - : _driver(driver) - , _note_num(note_num) -{ -} - - -void -JackNoteOnAction::execute(Timestamp time) -{ - SharedPtr 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 driver, - unsigned char note_num) - : _driver(driver) - , _note_num(note_num) -{ -} - - -void -JackNoteOffAction::execute(Timestamp time) -{ - SharedPtr 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 + * + * 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 +#include "machina/MidiAction.hpp" +#include "machina/MidiDriver.hpp" + +namespace Machina { + + +/* NOTE ON */ + +MidiAction(WeakPtr driver, + size_t size, + unsigned char* event) + : _driver(driver) + , _size(size) + , _event(event) +{ +} + + +void +MidiAction::execute(Timestamp time) +{ + SharedPtr 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/JackActions.hpp b/src/engine/machina/JackActions.hpp deleted file mode 100644 index 0eb50b8..0000000 --- a/src/engine/machina/JackActions.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007 Dave Robillard - * - * 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 - */ - -#ifndef MACHINA_JACKACTIONS_HPP -#define MACHINA_JACKACTIONS_HPP - -#include -#include "types.hpp" -#include "Action.hpp" - -namespace Machina { - -class Node; -class JackDriver; - - -class JackNoteOnAction : public Action { -public: - JackNoteOnAction(WeakPtr driver, unsigned char note_num); - - void execute(Timestamp time); - -private: - WeakPtr _driver; - unsigned char _note_num; -}; - - -class JackNoteOffAction : public Action { -public: - JackNoteOffAction(WeakPtr driver, unsigned char note_num); - - void execute(Timestamp time); - -private: - WeakPtr _driver; - unsigned char _note_num; -}; - - -} // namespace Machina - -#endif // MACHINA_JACKACTIONS_HPP 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 #include #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; } // 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; + 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/MidiAction.hpp b/src/engine/machina/MidiAction.hpp new file mode 100644 index 0000000..2e1d1fc --- /dev/null +++ b/src/engine/machina/MidiAction.hpp @@ -0,0 +1,47 @@ +/* This file is part of Machina. + * Copyright (C) 2007 Dave Robillard + * + * 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 + */ + +#ifndef MACHINA_MIDIACTION_HPP +#define MACHINA_MIDIACTION_HPP + +#include +#include "types.hpp" +#include "Action.hpp" + +namespace Machina { + +class MidiDriver; + + +class MidiAction : public Action { +public: + JackNoteOnAction(WeakPtr driver, + size_t size, + unsigned char* event); + + void execute(Timestamp time); + +private: + WeakPtr _driver; + size_t _size; + unsigned char* _event; +}; + + +} // namespace Machina + +#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 -- cgit v1.2.1