Browse Source

Tweak build system, midi.hpp structure

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
bd99a85595
5 changed files with 66 additions and 45 deletions
  1. +2
    -2
      Makefile
  2. +2
    -2
      include/bridge.hpp
  3. +4
    -2
      include/midi.hpp
  4. +23
    -18
      src/bridge.cpp
  5. +35
    -21
      src/midi.cpp

+ 2
- 2
Makefile View File

@@ -6,7 +6,7 @@ FLAGS += \
-Idep/include -Idep/lib/libzip/include -Idep/include -Idep/lib/libzip/include


ifdef RELEASE ifdef RELEASE
FLAGS += -DRELEASE=$(RELEASE)
FLAGS += -DRELEASE
endif endif


include arch.mk include arch.mk
@@ -29,7 +29,7 @@ endif


ifeq ($(ARCH), mac) ifeq ($(ARCH), mac)
SOURCES += dep/osdialog/osdialog_mac.m SOURCES += dep/osdialog/osdialog_mac.m
CXXFLAGS += -DAPPLE -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++ -lpthread -ldl \ LDFLAGS += -stdlib=libc++ -lpthread -ldl \
-framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \
-Ldep/lib -lGLEW -lglfw -ljansson -lspeexdsp -lcurl -lzip -lrtaudio -lrtmidi -lcrypto -lssl -Ldep/lib -lGLEW -lglfw -ljansson -lspeexdsp -lcurl -lzip -lrtaudio -lrtmidi -lcrypto -lssl


+ 2
- 2
include/bridge.hpp View File

@@ -9,8 +9,8 @@ namespace rack {


void bridgeInit(); void bridgeInit();
void bridgeDestroy(); void bridgeDestroy();
void bridgeMidiSubscribe(int channel, MidiIO *midi);
void bridgeMidiUnsubscribe(int channel, MidiIO *midi);
void bridgeMidiSubscribe(int channel, MidiInput *midi);
void bridgeMidiUnsubscribe(int channel, MidiInput *midi);
void bridgeAudioSubscribe(int channel, AudioIO *audio); void bridgeAudioSubscribe(int channel, AudioIO *audio);
void bridgeAudioUnsubscribe(int channel, AudioIO *audio); void bridgeAudioUnsubscribe(int channel, AudioIO *audio);




+ 4
- 2
include/midi.hpp View File

@@ -55,12 +55,11 @@ struct MidiIO {


int getDeviceCount(); int getDeviceCount();
std::string getDeviceName(int device); std::string getDeviceName(int device);
void setDevice(int device);
virtual void setDevice(int device) {}


std::string getChannelName(int channel); std::string getChannelName(int channel);
json_t *toJson(); json_t *toJson();
void fromJson(json_t *rootJ); void fromJson(json_t *rootJ);
virtual void onMessage(MidiMessage message) {}
}; };




@@ -69,6 +68,8 @@ struct MidiInput : MidiIO {
MidiInput(); MidiInput();
~MidiInput(); ~MidiInput();
void setDriver(int driver) override; void setDriver(int driver) override;
void setDevice(int device) override;
virtual void onMessage(MidiMessage message) {}
}; };




@@ -86,6 +87,7 @@ struct MidiOutput : MidiIO {
MidiOutput(); MidiOutput();
~MidiOutput(); ~MidiOutput();
void setDriver(int driver) override; void setDriver(int driver) override;
void setDevice(int device) override;
}; };






+ 23
- 18
src/bridge.cpp View File

@@ -3,7 +3,7 @@
#include "dsp/ringbuffer.hpp" #include "dsp/ringbuffer.hpp"


#include <unistd.h> #include <unistd.h>
#ifdef ARCH_WIN
#if ARCH_WIN
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <sys/socket.h> #include <sys/socket.h>
@@ -23,7 +23,7 @@ namespace rack {
struct BridgeClientConnection; struct BridgeClientConnection;
static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {}; static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {};
static AudioIO *audioListeners[BRIDGE_NUM_PORTS] = {}; static AudioIO *audioListeners[BRIDGE_NUM_PORTS] = {};
static MidiIO *midiListeners[BRIDGE_NUM_PORTS] = {};
static MidiInput *midiListeners[BRIDGE_NUM_PORTS] = {};
static std::thread serverThread; static std::thread serverThread;
static bool serverRunning = false; static bool serverRunning = false;


@@ -44,7 +44,7 @@ struct BridgeClientConnection {
if (length <= 0) if (length <= 0)
return false; return false;


#ifdef ARCH_LIN
#if ARCH_LIN
int flags = MSG_NOSIGNAL; int flags = MSG_NOSIGNAL;
#else #else
int flags = 0; int flags = 0;
@@ -71,7 +71,7 @@ struct BridgeClientConnection {
if (length <= 0) if (length <= 0)
return false; return false;


#ifdef ARCH_LIN
#if ARCH_LIN
int flags = MSG_NOSIGNAL; int flags = MSG_NOSIGNAL;
#else #else
int flags = 0; int flags = 0;
@@ -188,7 +188,7 @@ struct BridgeClientConnection {


void setPort(int port) { void setPort(int port) {
// Unbind from existing port // Unbind from existing port
if (this->port >= 0 && connections[this->port] == this) {
if (0 <= this->port && connections[this->port] == this) {
connections[this->port] = NULL; connections[this->port] = NULL;
} }


@@ -239,7 +239,7 @@ struct BridgeClientConnection {


static void clientRun(int client) { static void clientRun(int client) {
defer({ defer({
#ifdef ARCH_WIN
#if ARCH_WIN
if (shutdown(client, SD_SEND)) { if (shutdown(client, SD_SEND)) {
warn("Bridge client shutdown() failed"); warn("Bridge client shutdown() failed");
} }
@@ -253,7 +253,7 @@ static void clientRun(int client) {
#endif #endif
}); });


#ifdef ARCH_MAC
#if ARCH_MAC
// Avoid SIGPIPE // Avoid SIGPIPE
int flag = 1; int flag = 1;
if (setsockopt(client, SOL_SOCKET, SO_NOSIGPIPE, &flag, sizeof(int))) { if (setsockopt(client, SOL_SOCKET, SO_NOSIGPIPE, &flag, sizeof(int))) {
@@ -263,7 +263,7 @@ static void clientRun(int client) {
#endif #endif


// Disable non-blocking // Disable non-blocking
#ifdef ARCH_WIN
#if ARCH_WIN
unsigned long blockingMode = 0; unsigned long blockingMode = 0;
if (ioctlsocket(client, FIONBIO, &blockingMode)) { if (ioctlsocket(client, FIONBIO, &blockingMode)) {
warn("Bridge client ioctlsocket() failed"); warn("Bridge client ioctlsocket() failed");
@@ -284,7 +284,7 @@ static void clientRun(int client) {


static void serverConnect() { static void serverConnect() {
// Initialize sockets // Initialize sockets
#ifdef ARCH_WIN
#if ARCH_WIN
WSADATA wsaData; WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData)) { if (WSAStartup(MAKEWORD(2, 2), &wsaData)) {
warn("Bridge server WSAStartup() failed"); warn("Bridge server WSAStartup() failed");
@@ -300,7 +300,7 @@ static void serverConnect() {
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(BRIDGE_PORT); addr.sin_port = htons(BRIDGE_PORT);
#ifdef ARCH_WIN
#if ARCH_WIN
addr.sin_addr.s_addr = inet_addr(BRIDGE_HOST); addr.sin_addr.s_addr = inet_addr(BRIDGE_HOST);
#else #else
inet_pton(AF_INET, BRIDGE_HOST, &addr.sin_addr); inet_pton(AF_INET, BRIDGE_HOST, &addr.sin_addr);
@@ -313,9 +313,18 @@ static void serverConnect() {
return; return;
} }
defer({ defer({
close(server);
if (close(server)) {
warn("Bridge server close() failed");
return;
}
info("Bridge server closed");
}); });


#if ARCH_MAC || ARCH_LIN
int reuseAddrFlag = 1;
setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &reuseAddrFlag, sizeof(reuseAddrFlag));
#endif

// Bind socket to address // Bind socket to address
if (bind(server, (struct sockaddr*) &addr, sizeof(addr))) { if (bind(server, (struct sockaddr*) &addr, sizeof(addr))) {
warn("Bridge server bind() failed"); warn("Bridge server bind() failed");
@@ -330,7 +339,7 @@ static void serverConnect() {
info("Bridge server started"); info("Bridge server started");


// Enable non-blocking // Enable non-blocking
#ifdef ARCH_WIN
#if ARCH_WIN
unsigned long blockingMode = 1; unsigned long blockingMode = 1;
if (ioctlsocket(server, FIONBIO, &blockingMode)) { if (ioctlsocket(server, FIONBIO, &blockingMode)) {
warn("Bridge server ioctlsocket() failed"); warn("Bridge server ioctlsocket() failed");
@@ -354,8 +363,6 @@ static void serverConnect() {
std::thread clientThread(clientRun, client); std::thread clientThread(clientRun, client);
clientThread.detach(); clientThread.detach();
} }

info("Bridge server closed");
} }


static void serverRun() { static void serverRun() {
@@ -375,18 +382,16 @@ void bridgeDestroy() {
serverThread.join(); serverThread.join();
} }


void bridgeMidiSubscribe(int port, MidiIO *midi) {
void bridgeMidiSubscribe(int port, MidiInput *midi) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS)) if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return; return;
// Check if a Midi is already subscribed on the port // Check if a Midi is already subscribed on the port
if (midiListeners[port]) if (midiListeners[port])
return; return;
midiListeners[port] = midi; midiListeners[port] = midi;
if (connections[port])
connections[port]->refreshAudio();
} }


void bridgeMidiUnsubscribe(int port, MidiIO *midi) {
void bridgeMidiUnsubscribe(int port, MidiInput *midi) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS)) if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return; return;
if (midiListeners[port] != midi) if (midiListeners[port] != midi)


+ 35
- 21
src/midi.cpp View File

@@ -61,27 +61,6 @@ std::string MidiIO::getDeviceName(int device) {
return ""; return "";
} }


void MidiIO::setDevice(int device) {
if (rtMidi) {
rtMidi->closePort();

if (device >= 0) {
rtMidi->openPort(device);
deviceName = rtMidi->getPortName(device);
}
this->device = device;
}
else if (driver == BRIDGE_DRIVER) {
if (device >= 0) {
bridgeMidiSubscribe(device, this);
}
else {
bridgeMidiUnsubscribe(device, this);
}
this->device = device;
}
}

std::string MidiIO::getChannelName(int channel) { std::string MidiIO::getChannelName(int channel) {
if (channel == -1) if (channel == -1)
return "All channels"; return "All channels";
@@ -170,6 +149,27 @@ void MidiInput::setDriver(int driver) {
} }
} }


void MidiInput::setDevice(int device) {
if (rtMidi) {
rtMidi->closePort();

if (device >= 0) {
rtMidi->openPort(device);
deviceName = rtMidi->getPortName(device);
}
this->device = device;
}
else if (driver == BRIDGE_DRIVER) {
if (device >= 0) {
bridgeMidiSubscribe(device, this);
}
else {
bridgeMidiUnsubscribe(device, this);
}
this->device = device;
}
}

void MidiInputQueue::onMessage(MidiMessage message) { void MidiInputQueue::onMessage(MidiMessage message) {
// Filter channel // Filter channel
if (channel >= 0) { if (channel >= 0) {
@@ -218,5 +218,19 @@ void MidiOutput::setDriver(int driver) {
} }
} }


void MidiOutput::setDevice(int device) {
if (rtMidi) {
rtMidi->closePort();

if (device >= 0) {
rtMidi->openPort(device);
deviceName = rtMidi->getPortName(device);
}
this->device = device;
}
else if (driver == BRIDGE_DRIVER) {
}
}



} // namespace rack } // namespace rack

Loading…
Cancel
Save