Skip to content

Commit

Permalink
MIDI In support to aid on previewing the plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed May 20, 2019
1 parent c5fea10 commit 157e084
Show file tree
Hide file tree
Showing 23 changed files with 4,487 additions and 27 deletions.
48 changes: 27 additions & 21 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ opts.Add(EnumVariable("platform","Platform to build",detected_platform,("windows
opts.Add(BoolVariable("enable_rtaudio","Use RtAudio as Sound Driver",True))
opts.Add(BoolVariable("use_jack","Use Jack with RtAudio",False))
opts.Add(BoolVariable("use_pulseaudio","Use Pulseaudio with RtAudio",True))
opts.Add(BoolVariable("use_alsa","Use Alsa with RtAudio",True))
opts.Add(BoolVariable("use_alsa","Use Alsa with RtAudio and RtMidi",True))
opts.Add(BoolVariable("enable_vst2","Enable VST2",True))
opts.Add(BoolVariable("use_wasapi","Enable Wasapi",True))
opts.Add(BoolVariable("use_directsound","Enable Wasapi",True))
opts.Add(BoolVariable("enable_rtmidi","Use RtMidi as MIDI Driver",True))
opts.Add(BoolVariable("use_winmm","Enable WinMM for RtMidi",True))

opts.Update(env) # update environment
Help(opts.GenerateHelpText(env)) # generate help
Expand All @@ -37,36 +39,40 @@ if (detected_platform==""):
if (env["enable_rtaudio"]):

env.Append(CXXFLAGS=["-DRTAUDIO_ENABLED"])
if (env["platform"]=="windows"):
if (env["use_wasapi"]):
env.Append(CXXFLAGS=["-D__WINDOWS_WASAPI__"])
if (env["use_directsound"]):
env.Append(CXXFLAGS=["-D__WINDOWS_DS__"])
#env.Append(CXXFLAGS=["-D__WINDOWS_ASIO__"])
env.Append(LIBS=["dsound","mfplat","mfuuid","wmcodecdspuuid","ksuser"])

if (env["platform"]=="freedesktop"):

if (env["use_pulseaudio"]):
env.Append(CXXFLAGS=["-D__LINUX_PULSE__"])
env.ParseConfig("pkg-config libpulse --libs --cflags")
env.ParseConfig("pkg-config libpulse-simple --libs --cflags")
if (env["use_alsa"]):
env.Append(CXXFLAGS=["-D__LINUX_ALSA__"])
env.ParseConfig("pkg-config alsa --libs --cflags")
if (env["use_jack"]):
env.Append(CXXFLAGS=["-D__LINUX_JACK__"])
env.ParseConfig("pkg-config jack --libs --cflags")

if (env["enable_rtmidi"]):

env.Append(CXXFLAGS=["-DRTMIDI_ENABLED"])


if (env["platform"]=="windows"):
env.Append(CXXFLAGS=["-DWINDOWS_ENABLED"])
if (env["enable_vst2"]):
env.Append(CXXFLAGS=["-DVST2_ENABLED"])
if (env["use_wasapi"]):
env.Append(CXXFLAGS=["-D__WINDOWS_WASAPI__"])
if (env["use_directsound"]):
env.Append(CXXFLAGS=["-D__WINDOWS_DS__"])
if (env["use_winmm"]):
env.Append(CXXFLAGS=["-D__WINDOWS_MM__"])

#env.Append(CXXFLAGS=["-D__WINDOWS_ASIO__"])
env.Append(LIBS=["dsound","mfplat","mfuuid","wmcodecdspuuid","ksuser"])


if (env["platform"]=="freedesktop"):
env["enable_vst2"]=False # not supported
env.Append(CXXFLAGS=["-DFREEDESKTOP_ENABLED"])
if (env["use_pulseaudio"]):
env.Append(CXXFLAGS=["-D__LINUX_PULSE__"])
env.ParseConfig("pkg-config libpulse --libs --cflags")
env.ParseConfig("pkg-config libpulse-simple --libs --cflags")
if (env["use_alsa"]):
env.Append(CXXFLAGS=["-D__LINUX_ALSA__"])
env.ParseConfig("pkg-config alsa --libs --cflags")
if (env["use_jack"]):
env.Append(CXXFLAGS=["-D__LINUX_JACK__"])
env.ParseConfig("pkg-config jack --libs --cflags")

def add_sources(self, sources, filetype, lib_env = None, shared = False):
import glob;
Expand Down
26 changes: 23 additions & 3 deletions bin/zytrax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "drivers/rtaudio/sound_driver_rtaudio.h"
#endif

#ifdef RTMIDI_ENABLED
#include "drivers/rtmidi/midi_driver_rtmidi.h"
#endif
int main(int argc, char *argv[]) {

AudioEffectFactory effect_factory;
Expand All @@ -26,6 +29,9 @@ int main(int argc, char *argv[]) {
register_rtaudio_driver();
#endif

#ifdef RTMIDI_ENABLED
register_rtmidi_driver();
#endif
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");

Theme theme;
Expand All @@ -35,19 +41,21 @@ int main(int argc, char *argv[]) {
{
String path = SettingsDialog::get_settings_path() + "/settings.json";
JSON::Node node;
int use_driver_index = 0;
int use_driver_index = SoundDriverManager::get_driver_count() ? 0 : -1;
int use_midi_in_driver_index = MIDIDriverManager::get_input_driver_count() ? 0 : -1;

if (load_json(path, node) == OK) {

if (node.has("audio")) { //audio
JSON::Node audio_node = node.get("audio");
std::string driver_id = audio_node.get("id").toString();
int use_driver_index = -1;

for (int i = 0; i < SoundDriverManager::get_driver_count(); i++) {
SoundDriver *driver = SoundDriverManager::get_driver(i);
if (driver->get_id() == driver_id.c_str()) {
use_driver_index = i;
}
use_driver_index = i;

break;
}

Expand All @@ -65,6 +73,17 @@ int main(int argc, char *argv[]) {
if (block_size >= 0 && block_size < SoundDriverManager::BUFFER_SIZE_MAX) {
SoundDriverManager::set_step_buffer_size(SoundDriverManager::BufferSize(block_size));
}

std::string midi_driver_id = audio_node.get("midi_in_id").toString();

for (int i = 0; i < MIDIDriverManager::get_input_driver_count(); i++) {
MIDIInputDriver *driver = MIDIDriverManager::get_input_driver(i);
if (driver->get_id() == midi_driver_id.c_str()) {
use_midi_in_driver_index = i;
}

break;
}
}

if (node.has("plugins")) { //plugins
Expand Down Expand Up @@ -157,6 +176,7 @@ int main(int argc, char *argv[]) {
}
}
SoundDriverManager::init_driver(use_driver_index);
MIDIDriverManager::init_input_driver(use_midi_in_driver_index);
}

register_effects(&effect_factory);
Expand Down
4 changes: 4 additions & 0 deletions drivers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ if (env["enable_rtaudio"]):
env.add_sources(targets,"rtaudio/*.cpp")
env.add_sources(targets,"rtaudio/rtaudio/*.cpp")

if (env["enable_rtmidi"]):
env.add_sources(targets,"rtmidi/*.cpp")
env.add_sources(targets,"rtmidi/rtmidi/*.cpp")

env.libs+=env.Library('drivers', targets);
86 changes: 86 additions & 0 deletions drivers/rtmidi/midi_driver_rtmidi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "midi_driver_rtmidi.h"

#include "engine/midi_driver_manager.h"
#include "globals/vector.h"
//
#include "drivers/rtmidi/rtmidi/RtMidi.h"

static RtMidiIn *midiin = NULL;

class MIDIInputDriverRtMidi : public MIDIInputDriver {
public:
static void midi_callback(double deltatime, std::vector<unsigned char> *message, void *userData) {
MIDIInputDriverRtMidi *driver = (MIDIInputDriverRtMidi *)userData;
MIDIEvent ev;
if (ev.parse(&(*message)[0]) == OK) {
driver->event(deltatime, ev);
}
}

virtual void lock() {
}
virtual void unlock() {
}

String name;
String id;
int index;
bool active;

virtual String get_name() const {
return name;
}
virtual String get_id() const {
return id;
}

virtual bool is_active() {
return active;
}
virtual bool init() {
ERR_FAIL_COND_V(active, false);
midiin->openPort(index);
// Set our callback function. This should be done immediately after
// opening the port to avoid having incoming messages written to the
// queue.
midiin->setCallback(&midi_callback, this);
// Don't ignore sysex, timing, or active sensing messages.
midiin->ignoreTypes(false, false, false);
active = true;
}
virtual void finish() {
midiin->closePort();
active = false;
}

MIDIInputDriverRtMidi() {
index = -1;
active = false;
}
~MIDIInputDriverRtMidi() {
}
};

static Vector<MIDIInputDriverRtMidi *> midi_drivers;

void register_rtmidi_driver() {

midiin = new RtMidiIn();

unsigned int nPorts = midiin->getPortCount();
for (int i = 0; i < nPorts; i++) {
MIDIInputDriverRtMidi *driver = new MIDIInputDriverRtMidi;
driver->name.parse_utf8(midiin->getPortName(i).c_str());
driver->id = "RtMidi:" + driver->name;
driver->index = i;
midi_drivers.push_back(driver);
MIDIDriverManager::add_input_driver(driver);
}
}

void unregister_rtmidi_driver() {
for (int i = 0; i < midi_drivers.size(); i++) {
delete midi_drivers[i];
}
delete midiin;
}
9 changes: 9 additions & 0 deletions drivers/rtmidi/midi_driver_rtmidi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef MIDI_DRIVER_RTMIDI_H
#define MIDI_DRIVER_RTMIDI_H

//

void register_rtmidi_driver();
void unregister_rtmidi_driver();

#endif // MIDI_DRIVER_RTMIDI_H
Loading

0 comments on commit 157e084

Please sign in to comment.