New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic control of JACK/ALSA MIDI Out ports #1171

Merged
merged 1 commit into from Nov 28, 2014
Jump to file or symbol
Failed to load files and symbols.
+181 −127
Diff settings

Always

Just for now

View
@@ -322,6 +322,7 @@ void Score::init()
_tempomap = 0;
_layoutMode = LayoutMode::PAGE;
_noteHeadWidth = 0.0; // set in doLayout()
_midiPortCount = 0;
}
//---------------------------------------------------------
@@ -402,6 +403,7 @@ Score::Score(Score* parent, const MStyle* s)
Score::~Score()
{
_midiPortCount = 0;
foreach(MuseScoreView* v, viewer)
v->removeScore();
// deselectAll();
@@ -894,13 +896,16 @@ void Score::rebuildMidiMapping()
int port = 0;
int channel = 0;
int idx = 0;
int maxport = 0;
foreach(Part* part, _parts) {
InstrumentList* il = part->instrList();
for (auto i = il->begin(); i != il->end(); ++i) {
DrumsetKind drum = i->second.useDrumset();
for (int k = 0; k < i->second.channel().size(); ++k) {
Channel* a = &(i->second.channel(k));
MidiMapping mm;
if (port > maxport)
maxport = port;
if (drum != DrumsetKind::NONE) {
mm.port = port;
mm.channel = 9;
@@ -926,6 +931,31 @@ void Score::rebuildMidiMapping()
}
}
}
setMidiPortCount(maxport);
}
//---------------------------------------------------------
// midiPortCount
//---------------------------------------------------------
int Score::midiPortCount() const {
const Score* root = rootScore();
if (this == root)
return _midiPortCount;
else
return root->midiPortCount();
}
//---------------------------------------------------------
// setMidiPortCount
//---------------------------------------------------------
void Score::setMidiPortCount(int maxport) {
Score* root = rootScore();
if (this == root)
_midiPortCount = maxport;
else
root->setMidiPortCount(maxport);
}
//---------------------------------------------------------
View
@@ -378,6 +378,7 @@ class Score : public QObject {
qreal _noteHeadWidth;
QString accInfo; ///< information used by the screen-reader
int _midiPortCount; // A count of JACK/ALSA midi out ports. Stored in a root score
//------------------
@@ -757,6 +758,9 @@ class Score : public QObject {
void updateSwing();
void createPlayEvents();
int midiPortCount() const;
void setMidiPortCount(int);
void cmdConcertPitchChanged(bool, bool /*useSharpsFlats*/);
void setTempomap(TempoMap* tm);
View
@@ -764,6 +764,16 @@ void AlsaAudio::midiRead()
{
midiDriver->read();
}
//---------------------------------------------------------
// updateOutPortCount
// Add/remove ALSA MIDI Out ports
//---------------------------------------------------------
void AlsaAudio::updateOutPortCount(int maxport)
{
static_cast<AlsaMidiDriver*>(midiDriver)->updateInPortCount(maxport);
}
}
#endif
View
@@ -136,6 +136,7 @@ class AlsaAudio : public Driver {
void write(int n, void* l);
virtual void midiRead();
virtual void updateOutPortCount(int maxport);
};
}
View
@@ -56,6 +56,7 @@ class AlsaMidiDriver : public MidiDriver {
virtual void getOutputPollFd(struct pollfd**, int* n);
virtual void read();
virtual void write(const Event&);
virtual void updateInPortCount(int);
};
}
View
@@ -53,6 +53,7 @@ class Driver {
virtual void handleTimeSigTempoChanged() {}
virtual void checkTransportSeek(int, int, bool) {}
virtual int bufferSize() {return 0;}
virtual void updateOutPortCount(int) {}
};
View
@@ -59,6 +59,36 @@ JackAudio::~JackAudio()
}
}
//---------------------------------------------------------
// updateOutPortCount
// Add/remove JACK MIDI Out ports
//---------------------------------------------------------
void JackAudio::updateOutPortCount(int maxport)
{
if (!preferences.useJackMidi || maxport == midiOutputPorts.size())
return;
if (MScore::debugMode)
qDebug()<<"JACK number of ports:"<<midiOutputPorts.size()<<", change to:"<<maxport;
bool oldremember = preferences.rememberLastConnections;
preferences.rememberLastConnections = true;
if (maxport > midiOutputPorts.size()) {
for (int i = midiOutputPorts.size(); i < maxport; ++i)
registerPort(QString("mscore-midi-%1").arg(i+1), false, true);
restoreMidiConnections();
}
else if (maxport < midiOutputPorts.size()) {
rememberMidiConnections();
for(int i = midiOutputPorts.size() - 1; i >= maxport; --i) {
unregisterPort(midiOutputPorts[i]);
midiOutputPorts.removeAt(i);
}
}
preferences.rememberLastConnections = oldremember;
}
//---------------------------------------------------------
// registerPort
//---------------------------------------------------------
@@ -442,8 +472,7 @@ bool JackAudio::init(bool hot)
}
if (preferences.useJackMidi) {
for (int i = 0; i < preferences.midiPorts; ++i)
registerPort(QString("mscore-midi-%1").arg(i+1), false, true);
registerPort(QString("mscore-midi-1"), false, true);
registerPort(QString("mscore-midiin-1"), true, true);
}
return true;
@@ -908,25 +937,11 @@ void JackAudio::hotPlug()
// Midi connections
if (preferences.useJackMidi) {
if (midiOutputPorts.size()<preferences.midiPorts) {
for (int i = midiOutputPorts.size(); i < preferences.midiPorts; ++i)
registerPort(QString("mscore-midi-%1").arg(i+1), false, true);
}
else if (midiOutputPorts.size()>preferences.midiPorts) {
for(int i = midiOutputPorts.size()-1; i>=preferences.midiPorts; --i) {
unregisterPort(midiOutputPorts[i]);
midiOutputPorts.removeAt(i);
}
}
if (midiInputPorts.size() == 0)
registerPort(QString("mscore-midiin-1"), true, true);
}
else { // No midi
foreach(jack_port_t* mp, midiOutputPorts) {
unregisterPort(mp);
midiOutputPorts.removeOne(mp);
}
updateOutPortCount(0);
if (midiInputPorts.size() != 0) {
unregisterPort(midiInputPorts[0]);
midiInputPorts.removeOne(midiInputPorts[0]);
View
@@ -86,6 +86,7 @@ class JackAudio : public Driver {
virtual void checkTransportSeek(int, int, bool);
virtual int bufferSize() {return _segmentSize;}
void setBufferSize(int nframes) { _segmentSize = nframes;}
void updateOutPortCount(int);
};
View
@@ -160,10 +160,8 @@ bool AlsaMidiDriver::init()
qDebug("Alsa: Subscribe System failed: %s", snd_strerror(error));
return false;
}
midiOutPorts = new Port[preferences.midiPorts];
midiInPort = registerOutPort("MuseScore Port-0");
for (int i = 0; i < preferences.midiPorts; ++i)
midiOutPorts[i] = registerInPort(QString("MuseScore Port-%1").arg(i));
midiOutPorts.append(registerInPort("MuseScore Port-0"));
struct pollfd* pfd;
int npfd;
@@ -321,6 +319,31 @@ Port AlsaMidiDriver::registerInPort(const QString& name)
return Port(snd_seq_client_id(alsaSeq), alsaPort);
}
//---------------------------------------------------------
// updateInPortCount
//---------------------------------------------------------
void AlsaMidiDriver::updateInPortCount(int maxport)
{
int ports = midiOutPorts.size();
if (maxport == ports)
return;
if (MScore::debugMode)
qDebug()<<"ALSA number of ports:"<<ports<<", change to:"<<maxport;
if (maxport > ports) {
for (int i = ports; i < maxport; ++i)
midiOutPorts.append(registerInPort(QString("MuseScore Port-%1").arg(i)));
}
else if (maxport < ports) {
for(int i = ports - 1; i >= maxport; --i) {
if (snd_seq_delete_simple_port(alsaSeq, midiOutPorts[i].alsaPort()) < 0)
qDebug("Can not delete ALSA port");
else
midiOutPorts.removeAt(i);
}
}
}
//---------------------------------------------------------
// getInputPollFd
//---------------------------------------------------------
@@ -446,7 +469,7 @@ void AlsaMidiDriver::write(const Event& e)
snd_seq_event_t event;
memset(&event, 0, sizeof(event));
snd_seq_ev_set_direct(&event);
if (port >= preferences.midiPorts)
if (port >= midiOutPorts.size())
port = 0;
snd_seq_ev_set_source(&event, midiOutPorts[port].alsaPort());
snd_seq_ev_set_dest(&event, SND_SEQ_ADDRESS_SUBSCRIBERS, 0);
View
@@ -68,7 +68,7 @@ class Port {
class MidiDriver {
protected:
Port midiInPort;
Port* midiOutPorts;
QList<Port> midiOutPorts;
Seq* seq;
public:
View
@@ -130,7 +130,6 @@ void Preferences::init()
usePortaudioAudio = true;
#endif
midiPorts = 2;
rememberLastConnections = true;
alsaDevice = "default";
@@ -260,7 +259,6 @@ void Preferences::write()
s.setValue("jackTimebaseMaster", jackTimebaseMaster);
s.setValue("usePortaudioAudio", usePortaudioAudio);
s.setValue("usePulseAudio", usePulseAudio);
s.setValue("midiPorts", midiPorts);
s.setValue("rememberLastMidiConnections", rememberLastConnections);
s.setValue("alsaDevice", alsaDevice);
@@ -429,7 +427,6 @@ void Preferences::read()
MScore::playRepeats = s.value("playRepeats", MScore::playRepeats).toBool();
MScore::panPlayback = s.value("panPlayback", MScore::panPlayback).toBool();
alternateNoteEntryMethod = s.value("alternateNoteEntry", alternateNoteEntryMethod).toBool();
midiPorts = s.value("midiPorts", midiPorts).toInt();
rememberLastConnections = s.value("rememberLastMidiConnections", rememberLastConnections).toBool();
proximity = s.value("proximity", proximity).toInt();
autoSave = s.value("autoSave", autoSave).toBool();
@@ -857,7 +854,6 @@ void PreferenceDialog::updateValues()
case MusicxmlExportBreaks::NO: exportNoBreaks->setChecked(true); break;
}
midiPorts->setValue(prefs.midiPorts);
rememberLastMidiConnections->setChecked(prefs.rememberLastConnections);
proximity->setValue(prefs.proximity);
autoSave->setChecked(prefs.autoSave);
@@ -1282,7 +1278,6 @@ void PreferenceDialog::apply()
prefs.useJackTransport = jackDriver->isChecked() && useJackTransport->isChecked();
prefs.jackTimebaseMaster = becomeTimebaseMaster->isChecked();
prefs.midiPorts = midiPorts->value();
prefs.rememberLastConnections = rememberLastMidiConnections->isChecked();
bool wasJack = (prefs.useJackMidi || prefs.useJackAudio);
View
@@ -101,7 +101,6 @@ struct Preferences {
bool useJackMidi;
bool useJackTransport;
bool jackTimebaseMaster;
int midiPorts;
bool rememberLastConnections;
QString alsaDevice;
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.