Browse Source

Use 16 MIDI loopback devices instead of 1.

tags/v2.2.0
Andrew Belt 2 years ago
parent
commit
b4de7c9fc1
2 changed files with 29 additions and 11 deletions
  1. +2
    -1
      include/midiloopback.hpp
  2. +27
    -10
      src/midiloopback.cpp

+ 2
- 1
include/midiloopback.hpp View File

@@ -1,4 +1,5 @@
#pragma once #pragma once
#include <vector>
#include <common.hpp> #include <common.hpp>
#include <midi.hpp> #include <midi.hpp>


@@ -11,7 +12,7 @@ struct Device;




struct Context { struct Context {
Device* devices[1] = {};
std::vector<Device*> devices;


Context(); Context();
~Context(); ~Context();


+ 27
- 10
src/midiloopback.cpp View File

@@ -1,5 +1,6 @@
#include <context.hpp>
#include <midiloopback.hpp> #include <midiloopback.hpp>
#include <context.hpp>
#include <string.hpp>




namespace rack { namespace rack {
@@ -7,11 +8,14 @@ namespace midiloopback {




static const int DRIVER_ID = -12; static const int DRIVER_ID = -12;
static const size_t NUM_DEVICES = 16;




struct Device : midi::InputDevice, midi::OutputDevice { struct Device : midi::InputDevice, midi::OutputDevice {
int id = -1;

std::string getName() override { std::string getName() override {
return "Loopback";
return string::f("Loopback %d", id + 1);
} }


void sendMessage(const midi::Message& message) override { void sendMessage(const midi::Message& message) override {
@@ -27,7 +31,11 @@ struct Driver : midi::Driver {


// Input methods // Input methods
std::vector<int> getInputDeviceIds() override { std::vector<int> getInputDeviceIds() override {
return {0};
std::vector<int> deviceIds;
for (size_t i = 0; i < NUM_DEVICES; i++) {
deviceIds.push_back(i);
}
return deviceIds;
} }
int getDefaultInputDeviceId() override { int getDefaultInputDeviceId() override {
return 0; return 0;
@@ -51,13 +59,14 @@ struct Driver : midi::Driver {


// Output methods // Output methods
std::vector<int> getOutputDeviceIds() override { std::vector<int> getOutputDeviceIds() override {
return {0};
// Output IDs match input IDs
return getInputDeviceIds();
} }
int getDefaultOutputDeviceId() override { int getDefaultOutputDeviceId() override {
return 0;
return getDefaultInputDeviceId();
} }
std::string getOutputDeviceName(int deviceId) override { std::string getOutputDeviceName(int deviceId) override {
return getDevice(deviceId)->getName();
return getInputDeviceName(deviceId);
} }
midi::OutputDevice* subscribeOutput(int deviceId, midi::Output* output) override { midi::OutputDevice* subscribeOutput(int deviceId, midi::Output* output) override {
midi::OutputDevice* outputDevice = getDevice(deviceId); midi::OutputDevice* outputDevice = getDevice(deviceId);
@@ -77,19 +86,27 @@ struct Driver : midi::Driver {
Device* getDevice(int deviceId) { Device* getDevice(int deviceId) {
if (!APP->midiLoopbackContext) if (!APP->midiLoopbackContext)
return NULL; return NULL;
if (deviceId != 0)
if (!(0 <= deviceId && (size_t) deviceId < NUM_DEVICES))
return NULL; return NULL;
return APP->midiLoopbackContext->devices[deviceId];
Context* context = APP->midiLoopbackContext;
return context->devices[deviceId];
} }
}; };




Context::Context() { Context::Context() {
devices[0] = new Device;
for (size_t i = 0; i < NUM_DEVICES; i++) {
Device* device = new Device;
device->id = i;
devices.push_back(device);
}
} }


Context::~Context() { Context::~Context() {
delete devices[0];
for (Device* device : devices) {
delete device;
}
devices.clear();
} }






Loading…
Cancel
Save