Skip to content

Commit

Permalink
Basic JACK MIDI In support
Browse files Browse the repository at this point in the history
  • Loading branch information
Igevorse committed May 24, 2014
1 parent b4e6343 commit 0d0a350
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
3 changes: 2 additions & 1 deletion mscore/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Ms {

class Seq;
class Event;
class NPlayEvent;

//---------------------------------------------------------
// Driver
Expand All @@ -48,7 +49,7 @@ class Driver {
virtual int sampleRate() const = 0;
virtual void registerPort(const QString& /*name*/, bool /*input*/, bool /*midi*/) {}
virtual void unregisterPort(int) {}
virtual void putEvent(const Event&, unsigned /*framePos*/) {}
virtual void putEvent(const NPlayEvent&, unsigned /*framePos*/) {}
virtual void midiRead() {}
};

Expand Down
21 changes: 15 additions & 6 deletions mscore/jackaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ JackAudio::JackAudio(Seq* s)
JackAudio::~JackAudio()
{
if (client) {
stop();
if (jack_client_close(client)) {
qDebug("jack_client_close() failed: %s",
strerror(errno));
Expand Down Expand Up @@ -226,7 +227,7 @@ bool JackAudio::stop()
{
if (preferences.useJackMidi && preferences.rememberLastMidiConnections) {
QSettings settings;
settings.setValue("midiPorts", midiOutputPorts.size());
//settings.setValue("midiPorts", midiOutputPorts.size());
int port = 0;
foreach(jack_port_t* mp, midiOutputPorts) {
const char** cc = jack_port_get_connections(mp);
Expand All @@ -243,7 +244,8 @@ bool JackAudio::stop()
free((void*)cc);
++port;
}
settings.setValue("midiInputPorts", midiInputPorts.size());
// We don't use it now
//settings.setValue("midiInputPorts", midiInputPorts.size());
port = 0;
foreach(jack_port_t* mp, midiInputPorts) {
const char** cc = jack_port_get_connections(mp);
Expand Down Expand Up @@ -374,6 +376,11 @@ int JackAudio::processAudio(jack_nframes_t frames, void* p)
*r++ = *sp++;
}
}
else {
// JACK MIDI only
float buffer[frames * 2];
audio->seq->process((unsigned)frames, buffer);
}
return 0;
}

Expand All @@ -390,8 +397,9 @@ static void jackError(const char *s)
// noJackError
//---------------------------------------------------------

static void noJackError(const char* /* s */)
static void noJackError(const char* s )
{
qDebug("noJACK ERROR: %s", s);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -504,7 +512,7 @@ int JackAudio::getState()
// putEvent
//---------------------------------------------------------

void JackAudio::putEvent(const Event& e, unsigned framePos)
void JackAudio::putEvent(const NPlayEvent& e, unsigned framePos)
{
if (!preferences.useJackMidi)
return;
Expand Down Expand Up @@ -562,7 +570,8 @@ void JackAudio::putEvent(const Event& e, unsigned framePos)
p[1] = e.dataA();
}
break;
case ME_SYSEX:
// Do we really need to handle ME_SYSEX?
/* case ME_SYSEX:
{
const unsigned char* data = e.edata();
int len = e.len();
Expand All @@ -575,7 +584,7 @@ void JackAudio::putEvent(const Event& e, unsigned framePos)
p[len+1] = 0xf7;
memcpy(p+1, data, len);
}
break;
break;*/
case ME_SONGPOS:
case ME_CLOCK:
case ME_START:
Expand Down
2 changes: 1 addition & 1 deletion mscore/jackaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class JackAudio : public Driver {
virtual void stopTransport();
virtual int getState();
virtual int sampleRate() const { return jack_get_sample_rate(client); }
virtual void putEvent(const Event&, unsigned framePos);
virtual void putEvent(const NPlayEvent&, unsigned framePos);
virtual void midiRead();

virtual void registerPort(const QString& name, bool input, bool midi);
Expand Down
1 change: 1 addition & 0 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ void PreferenceDialog::updateValues()
portaudioDriver->setChecked(prefs.usePortaudioAudio);
pulseaudioDriver->setChecked(prefs.usePulseAudio);
useJackMidi->setChecked(prefs.useJackMidi);
useSynthesizer->setChecked(prefs.useAlsaAudio || prefs.useJackAudio || prefs.usePortaudioAudio || prefs.usePulseAudio);

alsaDevice->setText(prefs.alsaDevice);

Expand Down
22 changes: 18 additions & 4 deletions mscore/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ void Seq::process(unsigned n, float* buffer)
if (driverState != state) {
if (state == TRANSPORT_STOP && driverState == TRANSPORT_PLAY) {
state = TRANSPORT_PLAY;
// Changing GUI
if((preferences.useJackMidi || preferences.useJackAudio) && !getAction("play")->isChecked()) {
getAction("play")->setChecked(true);
getAction("play")->triggered(true);
}
if (mscore->countIn() && cs->playMode() == PLAYMODE_SYNTHESIZER) {
countInEvents.clear();
inCountIn = true;
Expand All @@ -660,10 +665,17 @@ void Seq::process(unsigned n, float* buffer)
}
else if (state == TRANSPORT_PLAY && driverState == TRANSPORT_STOP) {
state = TRANSPORT_STOP;
stopNotes();
// send sustain off
// TODO: channel?
putEvent(NPlayEvent(ME_CONTROLLER, 0, CTRL_SUSTAIN, 0));
// Muting all notes
if(preferences.useAlsaAudio || preferences.useJackAudio || preferences.usePulseAudio || preferences.usePortaudioAudio || preferences.useOsc)
stopNotes();
if(preferences.useJackMidi)
for(int ch=0; ch<cs->midiMapping()->size();ch++) {
// send sustain off
putEvent(NPlayEvent(ME_CONTROLLER, ch, CTRL_SUSTAIN, 0));
for(int i=0; i<128; i++)
putEvent(NPlayEvent(ME_NOTEOFF,ch,i,0));
}

if (playPos == events.cend()) {
if (mscore->loop()) {
qDebug("Seq.cpp - Process - Loop whole score. playPos = %d cs->pos() = %d", playPos->first,cs->pos());
Expand Down Expand Up @@ -1237,6 +1249,8 @@ void Seq::putEvent(const NPlayEvent& event)
}
int syntiIdx= _synti->index(cs->midiMapping(channel)->articulation->synti);
_synti->play(event, syntiIdx);
if (preferences.useJackMidi)
driver()->putEvent(event,0);
}

//---------------------------------------------------------
Expand Down

0 comments on commit 0d0a350

Please sign in to comment.