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

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

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

ifeq ($(ARCH), mac)
SOURCES += dep/osdialog/osdialog_mac.m
CXXFLAGS += -DAPPLE -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++ -lpthread -ldl \
-framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \
-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 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 bridgeAudioUnsubscribe(int channel, AudioIO *audio);



+ 4
- 2
include/midi.hpp View File

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

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

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


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


@@ -86,6 +87,7 @@ struct MidiOutput : MidiIO {
MidiOutput();
~MidiOutput();
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 <unistd.h>
#ifdef ARCH_WIN
#if ARCH_WIN
#include <winsock2.h>
#else
#include <sys/socket.h>
@@ -23,7 +23,7 @@ namespace rack {
struct BridgeClientConnection;
static BridgeClientConnection *connections[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 bool serverRunning = false;

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

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

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

void setPort(int 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;
}

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

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

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

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

static void serverConnect() {
// Initialize sockets
#ifdef ARCH_WIN
#if ARCH_WIN
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData)) {
warn("Bridge server WSAStartup() failed");
@@ -300,7 +300,7 @@ static void serverConnect() {
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(BRIDGE_PORT);
#ifdef ARCH_WIN
#if ARCH_WIN
addr.sin_addr.s_addr = inet_addr(BRIDGE_HOST);
#else
inet_pton(AF_INET, BRIDGE_HOST, &addr.sin_addr);
@@ -313,9 +313,18 @@ static void serverConnect() {
return;
}
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
if (bind(server, (struct sockaddr*) &addr, sizeof(addr))) {
warn("Bridge server bind() failed");
@@ -330,7 +339,7 @@ static void serverConnect() {
info("Bridge server started");

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

info("Bridge server closed");
}

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

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


+ 35
- 21
src/midi.cpp View File

@@ -61,27 +61,6 @@ std::string MidiIO::getDeviceName(int device) {
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) {
if (channel == -1)
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) {
// Filter channel
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

Loading…
Cancel
Save