earliest MIDI input! (no note input tho)
This commit is contained in:
parent
13a8873050
commit
5360cd73f4
15 changed files with 525 additions and 27 deletions
|
|
@ -55,4 +55,62 @@ bool TAAudio::init(TAAudioDesc& request, TAAudioDesc& response) {
|
|||
}
|
||||
|
||||
TAAudio::~TAAudio() {
|
||||
}
|
||||
|
||||
bool TAMidiIn::gather() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiIn::isDeviceOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiOut::isDeviceOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiIn::openDevice(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiOut::openDevice(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiIn::closeDevice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiOut::closeDevice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<String> TAMidiIn::listDevices() {
|
||||
return std::vector<String>();
|
||||
}
|
||||
|
||||
std::vector<String> TAMidiOut::listDevices() {
|
||||
return std::vector<String>();
|
||||
}
|
||||
|
||||
bool TAMidiIn::init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiOut::init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiIn::quit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TAMidiOut::quit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
TAMidiIn::~TAMidiIn() {
|
||||
}
|
||||
|
||||
TAMidiOut::~TAMidiOut() {
|
||||
}
|
||||
|
|
@ -52,6 +52,7 @@ void TAAudioJACK::onBufferSize(jack_nframes_t bufsize) {
|
|||
|
||||
void TAAudioJACK::onProcess(jack_nframes_t nframes) {
|
||||
if (audioProcCallback!=NULL) {
|
||||
if (midiIn!=NULL) midiIn->gather();
|
||||
audioProcCallback(audioProcCallbackUser,inBufs,outBufs,desc.inChans,desc.outChans,desc.bufsize);
|
||||
}
|
||||
for (int i=0; i<desc.inChans; i++) {
|
||||
|
|
|
|||
61
src/audio/midi.cpp
Normal file
61
src/audio/midi.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 more 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "taAudio.h"
|
||||
#ifdef HAVE_RTMIDI
|
||||
#include "rtmidi.h"
|
||||
#endif
|
||||
|
||||
bool TAAudio::initMidi(bool jack) {
|
||||
#ifndef HAVE_RTMIDI
|
||||
return false;
|
||||
#else
|
||||
midiIn=new TAMidiInRtMidi;
|
||||
midiOut=new TAMidiOutRtMidi;
|
||||
|
||||
if (!midiIn->init()) {
|
||||
delete midiIn;
|
||||
midiIn=NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!midiOut->init()) {
|
||||
midiIn->quit();
|
||||
delete midiOut;
|
||||
delete midiIn;
|
||||
midiOut=NULL;
|
||||
midiIn=NULL;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TAAudio::quitMidi() {
|
||||
if (midiIn!=NULL) {
|
||||
midiIn->quit();
|
||||
delete midiIn;
|
||||
midiIn=NULL;
|
||||
}
|
||||
if (midiOut!=NULL) {
|
||||
midiOut->quit();
|
||||
delete midiOut;
|
||||
midiOut=NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1,201 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 more 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "rtmidi.h"
|
||||
#include "../ta-log.h"
|
||||
|
||||
// --- IN ---
|
||||
|
||||
bool TAMidiInRtMidi::gather() {
|
||||
std::vector<unsigned char> msg;
|
||||
if (port==NULL) return false;
|
||||
while (true) {
|
||||
TAMidiMessage m;
|
||||
double t=port->getMessage(&msg);
|
||||
if (msg.empty()) break;
|
||||
|
||||
// parse message
|
||||
m.time=t;
|
||||
m.type=msg[0];
|
||||
if (m.type!=TA_MIDI_SYSEX && msg.size()>1) {
|
||||
memcpy(m.data,msg.data()+1,MIN(msg.size()-1,7));
|
||||
}
|
||||
queue.push(m);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<String> TAMidiInRtMidi::listDevices() {
|
||||
std::vector<String> ret;
|
||||
logD("listing devices.\n");
|
||||
if (port==NULL) return ret;
|
||||
|
||||
try {
|
||||
unsigned int count=port->getPortCount();
|
||||
logD("got port count.\n");
|
||||
for (unsigned int i=0; i<count; i++) {
|
||||
String name=port->getPortName(i);
|
||||
if (name!="") ret.push_back(name);
|
||||
}
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not get MIDI inputs! %s\n",e.what());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool TAMidiInRtMidi::isDeviceOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
bool TAMidiInRtMidi::openDevice(String name) {
|
||||
if (port==NULL) return false;
|
||||
if (isOpen) return false;
|
||||
try {
|
||||
bool portOpen=false;
|
||||
unsigned int count=port->getPortCount();
|
||||
for (unsigned int i=0; i<count; i++) {
|
||||
if (port->getPortName(i)==name) {
|
||||
port->openPort(i);
|
||||
portOpen=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isOpen=portOpen;
|
||||
return portOpen;
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not open MIDI in device! %s\n",e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TAMidiInRtMidi::closeDevice() {
|
||||
if (port==NULL) return false;
|
||||
if (!isOpen) return false;
|
||||
try {
|
||||
port->closePort();
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not close MIDI in device! %s\n",e.what());
|
||||
isOpen=false; // still
|
||||
return false;
|
||||
}
|
||||
isOpen=false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TAMidiInRtMidi::init() {
|
||||
if (port!=NULL) return true;
|
||||
try {
|
||||
port=new RtMidiIn;
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not initialize RtMidi in! %s\n",e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TAMidiInRtMidi::quit() {
|
||||
if (port!=NULL) {
|
||||
delete port;
|
||||
port=NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- OUT ---
|
||||
|
||||
bool TAMidiOutRtMidi::send(TAMidiMessage& what) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TAMidiOutRtMidi::isDeviceOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
bool TAMidiOutRtMidi::openDevice(String name) {
|
||||
if (port==NULL) return false;
|
||||
if (isOpen) return false;
|
||||
try {
|
||||
bool portOpen=false;
|
||||
unsigned int count=port->getPortCount();
|
||||
for (unsigned int i=0; i<count; i++) {
|
||||
if (port->getPortName(i)==name) {
|
||||
port->openPort(i);
|
||||
portOpen=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isOpen=portOpen;
|
||||
return portOpen;
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not open MIDI out device! %s\n",e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TAMidiOutRtMidi::closeDevice() {
|
||||
if (port==NULL) return false;
|
||||
if (!isOpen) return false;
|
||||
try {
|
||||
port->closePort();
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not close MIDI out device! %s\n",e.what());
|
||||
isOpen=false; // still
|
||||
return false;
|
||||
}
|
||||
isOpen=false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<String> TAMidiOutRtMidi::listDevices() {
|
||||
std::vector<String> ret;
|
||||
if (port==NULL) return ret;
|
||||
|
||||
try {
|
||||
unsigned int count=port->getPortCount();
|
||||
for (unsigned int i=0; i<count; i++) {
|
||||
String name=port->getPortName(i);
|
||||
if (name!="") ret.push_back(name);
|
||||
}
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not get MIDI outputs! %s\n",e.what());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool TAMidiOutRtMidi::init() {
|
||||
if (port!=NULL) return true;
|
||||
try {
|
||||
port=new RtMidiOut;
|
||||
} catch (RtMidiError& e) {
|
||||
logW("could not initialize RtMidi out! %s\n",e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TAMidiOutRtMidi::quit() {
|
||||
if (port!=NULL) {
|
||||
delete port;
|
||||
port=NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -21,9 +21,33 @@
|
|||
#include "taAudio.h"
|
||||
|
||||
class TAMidiInRtMidi: public TAMidiIn {
|
||||
|
||||
RtMidiIn* port;
|
||||
bool isOpen;
|
||||
public:
|
||||
bool gather();
|
||||
bool isDeviceOpen();
|
||||
bool openDevice(String name);
|
||||
bool closeDevice();
|
||||
std::vector<String> listDevices();
|
||||
bool quit();
|
||||
bool init();
|
||||
TAMidiInRtMidi():
|
||||
port(NULL),
|
||||
isOpen(false) {}
|
||||
};
|
||||
|
||||
class TAMidiOutRtMidi: public TAMidiOut {
|
||||
|
||||
RtMidiOut* port;
|
||||
bool isOpen;
|
||||
public:
|
||||
bool send(TAMidiMessage& what);
|
||||
bool isDeviceOpen();
|
||||
bool openDevice(String name);
|
||||
bool closeDevice();
|
||||
std::vector<String> listDevices();
|
||||
bool quit();
|
||||
bool init();
|
||||
TAMidiOutRtMidi():
|
||||
port(NULL),
|
||||
isOpen(false) {}
|
||||
};
|
||||
|
|
@ -30,6 +30,7 @@ void taSDLProcess(void* inst, unsigned char* buf, int nframes) {
|
|||
|
||||
void TAAudioSDL::onProcess(unsigned char* buf, int nframes) {
|
||||
if (audioProcCallback!=NULL) {
|
||||
if (midiIn!=NULL) midiIn->gather();
|
||||
audioProcCallback(audioProcCallbackUser,inBufs,outBufs,desc.inChans,desc.outChans,desc.bufsize);
|
||||
}
|
||||
float* fbuf=(float*)buf;
|
||||
|
|
|
|||
|
|
@ -90,28 +90,9 @@ enum TAMidiMessageTypes {
|
|||
};
|
||||
|
||||
struct TAMidiMessage {
|
||||
double time;
|
||||
unsigned char type;
|
||||
union {
|
||||
struct {
|
||||
unsigned char note, vol;
|
||||
} note;
|
||||
struct {
|
||||
unsigned char which, val;
|
||||
} control;
|
||||
unsigned char patch;
|
||||
unsigned char pressure;
|
||||
struct {
|
||||
unsigned char low, high;
|
||||
} pitch;
|
||||
struct {
|
||||
unsigned int vendor;
|
||||
} sysEx;
|
||||
unsigned char timeCode;
|
||||
struct {
|
||||
unsigned char low, high;
|
||||
} position;
|
||||
unsigned char song;
|
||||
} data;
|
||||
unsigned char data[7];
|
||||
unsigned char* sysExData;
|
||||
size_t sysExLen;
|
||||
|
||||
|
|
@ -119,6 +100,7 @@ struct TAMidiMessage {
|
|||
void done();
|
||||
|
||||
TAMidiMessage():
|
||||
time(0.0),
|
||||
type(0),
|
||||
sysExData(NULL),
|
||||
sysExLen(0) {
|
||||
|
|
@ -127,16 +109,34 @@ struct TAMidiMessage {
|
|||
};
|
||||
|
||||
class TAMidiIn {
|
||||
std::queue<TAMidiMessage> queue;
|
||||
public:
|
||||
std::queue<TAMidiMessage> queue;
|
||||
virtual bool gather();
|
||||
bool next(TAMidiMessage& where);
|
||||
virtual bool isDeviceOpen();
|
||||
virtual bool openDevice(String name);
|
||||
virtual bool closeDevice();
|
||||
virtual std::vector<String> listDevices();
|
||||
virtual bool init();
|
||||
virtual bool quit();
|
||||
TAMidiIn() {
|
||||
}
|
||||
virtual ~TAMidiIn();
|
||||
};
|
||||
|
||||
class TAMidiOut {
|
||||
std::queue<TAMidiMessage> queue;
|
||||
public:
|
||||
bool send(TAMidiMessage& what);
|
||||
virtual bool isDeviceOpen();
|
||||
virtual bool openDevice(String name);
|
||||
virtual bool closeDevice();
|
||||
virtual std::vector<String> listDevices();
|
||||
virtual bool init();
|
||||
virtual bool quit();
|
||||
TAMidiOut() {
|
||||
}
|
||||
virtual ~TAMidiOut();
|
||||
};
|
||||
|
||||
class TAAudio {
|
||||
|
|
@ -162,6 +162,8 @@ class TAAudio {
|
|||
virtual bool quit();
|
||||
virtual bool setRun(bool run);
|
||||
virtual std::vector<String> listAudioDevices();
|
||||
bool initMidi(bool jack);
|
||||
void quitMidi();
|
||||
virtual bool init(TAAudioDesc& request, TAAudioDesc& response);
|
||||
|
||||
TAAudio():
|
||||
|
|
@ -172,7 +174,9 @@ class TAAudio {
|
|||
outBufs(NULL),
|
||||
audioProcCallback(NULL),
|
||||
sampleRateChanged(NULL),
|
||||
bufferSizeChanged(NULL) {}
|
||||
bufferSizeChanged(NULL),
|
||||
midiIn(NULL),
|
||||
midiOut(NULL) {}
|
||||
|
||||
virtual ~TAAudio();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue