prepare for JACK MIDI support

This commit is contained in:
tildearrow 2023-05-10 04:11:37 -05:00
parent 29688d1cc5
commit 718a6f9f83
9 changed files with 124 additions and 19 deletions

View File

@ -290,7 +290,7 @@ endif()
if (WITH_JACK)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JACK REQUIRED jack)
list(APPEND AUDIO_SOURCES src/audio/jack.cpp)
list(APPEND AUDIO_SOURCES src/audio/jack.cpp src/audio/jackmidi.cpp)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${JACK_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_DEFINES HAVE_JACK)
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${JACK_CFLAGS_OTHER})

View File

@ -55,6 +55,10 @@ bool TAAudio::init(TAAudioDesc& request, TAAudioDesc& response) {
return true;
}
unsigned char TAAudio::getID() {
return 0;
}
TAAudio::~TAAudio() {
}

View File

@ -255,3 +255,8 @@ bool TAAudioJACK::init(TAAudioDesc& request, TAAudioDesc& response) {
initialized=true;
return true;
}
unsigned char TAAudioJACK::getID() {
return 'J';
}

View File

@ -21,6 +21,42 @@
#include <jack/weakjack.h>
#include <jack/jack.h>
class TAMidiInJACK: public TAMidiIn {
jack_client_t* ac;
jack_port_t* port;
bool isOpen;
public:
bool gather();
bool isDeviceOpen();
bool openDevice(String name);
bool closeDevice();
std::vector<String> listDevices();
bool quit();
bool init();
TAMidiInJACK(jack_client_t* client):
ac(client),
port(NULL),
isOpen(false) {}
};
class TAMidiOutJACK: public TAMidiOut {
jack_client_t* ac;
jack_port_t* port;
bool isOpen;
public:
bool send(const TAMidiMessage& what);
bool isDeviceOpen();
bool openDevice(String name);
bool closeDevice();
std::vector<String> listDevices();
bool quit();
bool init();
TAMidiOutJACK(jack_client_t* client):
ac(client),
port(NULL),
isOpen(false) {}
};
class TAAudioJACK: public TAAudio {
jack_client_t* ac;
jack_port_t** ai;
@ -40,6 +76,7 @@ class TAAudioJACK: public TAAudio {
bool quit();
bool setRun(bool run);
bool init(TAAudioDesc& request, TAAudioDesc& response);
unsigned char getID();
TAAudioJACK():
ac(NULL),

21
src/audio/jackmidi.cpp Normal file
View File

@ -0,0 +1,21 @@
/**
* Furnace Tracker - multi-system chiptune tracker
* Copyright (C) 2021-2023 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"
#include "jack.h"

View File

@ -21,30 +21,62 @@
#ifdef HAVE_RTMIDI
#include "rtmidi.h"
#endif
#ifdef HAVE_JACK
#include "jack.h"
#endif
bool TAAudio::initMidi(bool jack) {
#ifndef HAVE_RTMIDI
return false;
if (jack) {
#ifndef HAVE_JACK
return false;
#else
midiIn=new TAMidiInRtMidi;
midiOut=new TAMidiOutRtMidi;
if (getID()!='J') {
return false;
}
midiIn=new TAMidiInJACK((jack_client_t*)getContext());
midiOut=new TAMidiOutJACK((jack_client_t*)getContext());
if (!midiIn->init()) {
delete midiIn;
midiIn=NULL;
return false;
}
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;
if (!midiOut->init()) {
midiIn->quit();
delete midiOut;
delete midiIn;
midiOut=NULL;
midiIn=NULL;
return false;
}
return true;
#endif
} else {
#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() {

View File

@ -152,3 +152,7 @@ bool TAAudioSDL::init(TAAudioDesc& request, TAAudioDesc& response) {
initialized=true;
return true;
}
unsigned char TAAudioSDL::getID() {
return 'S';
}

View File

@ -33,6 +33,7 @@ class TAAudioSDL: public TAAudio {
bool setRun(bool run);
std::vector<String> listAudioDevices();
bool init(TAAudioDesc& request, TAAudioDesc& response);
unsigned char getID();
TAAudioSDL():
audioSysStarted(false) {}
};

View File

@ -176,6 +176,7 @@ class TAAudio {
bool initMidi(bool jack);
void quitMidi();
virtual bool init(TAAudioDesc& request, TAAudioDesc& response);
virtual unsigned char getID();
TAAudio():
outFormat(TA_AUDIO_FORMAT_F32),