summaryrefslogtreecommitdiff
path: root/muse2/muse/midiseq.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/muse/midiseq.cpp')
-rw-r--r--muse2/muse/midiseq.cpp135
1 files changed, 83 insertions, 52 deletions
diff --git a/muse2/muse/midiseq.cpp b/muse2/muse/midiseq.cpp
index aaf3f7dd..2f1174cd 100644
--- a/muse2/muse/midiseq.cpp
+++ b/muse2/muse/midiseq.cpp
@@ -6,6 +6,21 @@
// high priority task for scheduling midi events
//
// (C) Copyright 2003 Werner Schweer (ws@seh.de)
+//
+// 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; 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 <QMessageBox>
@@ -59,20 +74,25 @@ void MidiSeq::processMsg(const ThreadMsg* m)
//case MS_PROCESS:
// audio->processMidi();
// break;
- case SEQM_SEEK:
- processSeek();
- break;
- case MS_STOP:
- processStop();
- break;
+
+ // Removed p4.0.34
+ //case SEQM_SEEK:
+ // processSeek();
+ // break;
+ //case MS_STOP:
+ // processStop();
+ // break;
+
case MS_SET_RTC:
- doSetuid();
+ MusEGlobal::doSetuid();
setRtcTicks();
- undoSetuid();
+ MusEGlobal::undoSetuid();
break;
case MS_UPDATE_POLL_FD:
updatePollFd();
break;
+ // Moved into Song::processMsg p4.0.34
+ /*
case SEQM_ADD_TRACK:
song->insertTrack2(msg->track, msg->ival);
updatePollFd();
@@ -95,6 +115,7 @@ void MidiSeq::processMsg(const ThreadMsg* m)
//song->cmdChangePart((Part*)msg->p1, (Part*)msg->p2);
song->cmdChangePart((Part*)msg->p1, (Part*)msg->p2, msg->a, msg->b);
break;
+ */
case SEQM_SET_TRACK_OUT_CHAN:
{
MidiTrack* track = (MidiTrack*)(msg->p1);
@@ -126,6 +147,8 @@ void MidiSeq::processMsg(const ThreadMsg* m)
}
}
+#if 0
+// Removed p4.0.34
//---------------------------------------------------------
// processStop
//---------------------------------------------------------
@@ -133,8 +156,8 @@ void MidiSeq::processMsg(const ThreadMsg* m)
void MidiSeq::processStop()
{
// p3.3.28
- // TODO Try to move this into Audio::stopRolling(). p4.0.22
- playStateExt = false; // not playing
+ // TODO Try to move this into Audio::stopRolling(). p4.0.22 // Done p4.0.34
+ //playStateExt = false; // not playing
//
// clear Alsa midi device notes and stop stuck notes
@@ -142,10 +165,10 @@ void MidiSeq::processStop()
//
for(iMidiDevice id = midiDevices.begin(); id != midiDevices.end(); ++id)
{
- MidiDevice* md = *id;
- if(md->deviceType() == MidiDevice::JACK_MIDI) // p4.0.22
- continue;
- md->handleStop(); // p4.0.22
+ //MidiDevice* md = *id;
+ // Only ALSA devices are handled by this thread.
+ if((*id)->deviceType() == MidiDevice::ALSA_MIDI) // p4.0.22
+ (*id)->handleStop(); // p4.0.22
/*
if (md->midiPort() == -1)
continue;
@@ -163,18 +186,20 @@ void MidiSeq::processStop()
*/
}
}
+#endif
+#if 0
+// Removed p4.0.34
//---------------------------------------------------------
// processSeek
//---------------------------------------------------------
void MidiSeq::processSeek()
{
- int pos = audio->tickPos();
-
- // TODO Try to move this into audio::seek(). p4.0.22
- if (pos == 0 && !song->record())
- audio->initDevices();
+ //int pos = audio->tickPos();
+ // TODO Try to move this into audio::seek(). p4.0.22 Done p4.0.34
+ //if (pos == 0 && !song->record())
+ // audio->initDevices();
//---------------------------------------------------
// set all controller
@@ -182,13 +207,10 @@ void MidiSeq::processSeek()
for (iMidiDevice i = midiDevices.begin(); i != midiDevices.end(); ++i)
{
- MidiDevice* md = *i;
- //
- // Jack midi devices are handled in Audio::seek()
- //
- if(md->deviceType() == MidiDevice::JACK_MIDI) // p4.0.22
- continue;
- md->handleSeek(); // p4.0.22
+ //MidiDevice* md = *i;
+ // Only ALSA devices are handled by this thread.
+ if((*i)->deviceType() == MidiDevice::ALSA_MIDI) // p4.0.22
+ (*i)->handleSeek(); // p4.0.22
/*
int port = md->midiPort();
if (port == -1)
@@ -239,6 +261,7 @@ void MidiSeq::processSeek()
*/
}
}
+#endif
//---------------------------------------------------------
// MidiSeq
@@ -261,9 +284,9 @@ MidiSeq::MidiSeq(const char* name)
lastTempo = 0;
storedtimediffs = 0;
playStateExt = false; // not playing
- doSetuid();
+ MusEGlobal::doSetuid();
timerFd=selectTimer();
- undoSetuid();
+ MusEGlobal::undoSetuid();
}
@@ -399,7 +422,7 @@ void MidiSeq::updatePollFd()
if (timerFd == -1) {
fprintf(stderr, "updatePollFd: no timer fd\n");
- if (!debugMode)
+ if (!MusEGlobal::debugMode)
exit(-1);
}
@@ -412,7 +435,7 @@ void MidiSeq::updatePollFd()
for (iMidiDevice imd = midiDevices.begin(); imd != midiDevices.end(); ++imd) {
MidiDevice* dev = *imd;
int port = dev->midiPort();
- const QString name = dev->name();
+ //const QString name = dev->name();
if (port == -1)
continue;
if ((dev->rwFlags() & 0x2) || (extSyncFlag.value()
@@ -457,11 +480,11 @@ void MidiSeq::threadStop()
bool MidiSeq::setRtcTicks()
{
- //timer.setTimerFreq(config.rtcTicks);
+ //timer.setTimerFreq(MusEConfig::config.rtcTicks);
//timer.startTimer();
- timer->setTimerFreq(config.rtcTicks);
+ timer->setTimerFreq(MusEConfig::config.rtcTicks);
timer->startTimer();
- realRtcTicks = config.rtcTicks;
+ realRtcTicks = MusEConfig::config.rtcTicks;
return true;
}
@@ -479,12 +502,12 @@ void MidiSeq::start(int priority)
//timerFd = -1;
- doSetuid();
+ MusEGlobal::doSetuid();
//timerFd = selectTimer();
//timerFd = timer.initTimer();
//printf("timerFd=%d\n",timerFd);
setRtcTicks();
- undoSetuid();
+ MusEGlobal::undoSetuid();
//Thread::start();
Thread::start(priority);
//return false;
@@ -511,7 +534,7 @@ void MidiSeq::processMidiClock()
midiClick = sigmap.bar2tick(bar, beat+1, 0);
double cpos = tempomap.tick2time(playTickPos);
- samplePosStart = samplePos - lrint(cpos * sampleRate);
+ samplePosStart = samplePos - lrint(cpos * MusEGlobal::sampleRate);
rtcTickStart = rtcTick - lrint(cpos * realRtcTicks);
endSlice = playTickPos;
@@ -523,7 +546,7 @@ void MidiSeq::processMidiClock()
startRecordPos.setPosTick(playTickPos);
}
*/
-// midiClock += config.division/24;
+// midiClock += MusEConfig::config.division/24;
}
//---------------------------------------------------------
@@ -593,10 +616,10 @@ void MidiSeq::processTimerTick()
if (!extSyncFlag.value()) {
//int curTick = tempomap.frame2tick(curFrame);
// Copied from Tempomap.
- //int curTick = lrint((double(curFrame)/double(sampleRate)) * tempomap.globalTempo() * config.division * 10000.0 / double(tempomap.tempo(song->cpos())));
- //int curTick = lrint((double(curFrame)/double(sampleRate)) * tempomap.globalTempo() * 240000.0 / double(tempomap.tempo(song->cpos())));
- int curTick = lrint((double(curFrame)/double(sampleRate)) * double(tempomap.globalTempo()) * double(config.division) * 10000.0 / double(tempomap.tempo(song->cpos())));
- //int curTick = int((double(curFrame)/double(sampleRate)) * double(tempomap.globalTempo()) * double(config.division * 10000.0) / double(tempomap.tempo(song->cpos())));
+ //int curTick = lrint((double(curFrame)/double(MusEGlobal::sampleRate)) * tempomap.globalTempo() * MusEConfig::config.division * 10000.0 / double(tempomap.tempo(song->cpos())));
+ //int curTick = lrint((double(curFrame)/double(MusEGlobal::sampleRate)) * tempomap.globalTempo() * 240000.0 / double(tempomap.tempo(song->cpos())));
+ int curTick = lrint((double(curFrame)/double(MusEGlobal::sampleRate)) * double(tempomap.globalTempo()) * double(MusEConfig::config.division) * 10000.0 / double(tempomap.tempo(song->cpos())));
+ //int curTick = int((double(curFrame)/double(MusEGlobal::sampleRate)) * double(tempomap.globalTempo()) * double(MusEConfig::config.division * 10000.0) / double(tempomap.tempo(song->cpos())));
/* if ( midiClock > curTick + 100) // reinitialize
{
@@ -610,7 +633,7 @@ void MidiSeq::processTimerTick()
if(midiClock > curTick)
midiClock = curTick;
- int div = config.division/24;
+ int div = MusEConfig::config.division/24;
if(curTick >= midiClock + div) {
//if(curTick >= midiClock) {
//processMidiClock();
@@ -674,7 +697,7 @@ void MidiSeq::processTimerTick()
}
*/
- if(debugMsg && used && perr > 1)
+ if(MusEGlobal::debugMsg && used && perr > 1)
printf("Dropped %d midi out clock(s). curTick:%d midiClock:%d div:%d\n", perr, curTick, midiClock, div);
//}
@@ -710,20 +733,26 @@ void MidiSeq::processTimerTick()
// }
// p3.3.25
- int tickpos = audio->tickPos();
- bool extsync = extSyncFlag.value();
+ //int tickpos = audio->tickPos();
+ //bool extsync = extSyncFlag.value();
//
// play all events upto curFrame
//
for (iMidiDevice id = midiDevices.begin(); id != midiDevices.end(); ++id) {
- MidiDevice* md = *id;
+ //MidiDevice* md = *id;
// Is it a Jack midi device? They are iterated in Audio::processMidi. p3.3.36
//MidiJackDevice* mjd = dynamic_cast<MidiJackDevice*>(md);
//if(mjd)
- if(md->deviceType() == MidiDevice::JACK_MIDI)
- continue;
- if(md->isSynti()) // syntis are handled by audio thread
- continue;
+ //if(md->deviceType() == MidiDevice::JACK_MIDI)
+ // continue;
+ //if(md->isSynti()) // syntis are handled by audio thread
+ // continue;
+ // Only ALSA midi devices are handled by this thread.
+ if((*id)->deviceType() == MidiDevice::ALSA_MIDI)
+ (*id)->processMidi();
+
+ // Moved into MidiAlsaDevice. p4.0.34
+ /*
int port = md->midiPort();
MidiPort* mp = port != -1 ? &midiPorts[port] : 0;
MPEventList* el = md->playEvents();
@@ -761,6 +790,8 @@ void MidiSeq::processTimerTick()
// The erasure in Audio::processMidi was missing some events because of that.
el->erase(el->begin(), i);
//md->setNextPlayEvent(el->begin()); // Removed p4.0.15
+ */
+
}
}
@@ -798,8 +829,8 @@ void MidiSeq::msgSetMidiDevice(MidiPort* port, MidiDevice* device)
// This does not appear to be used anymore. Was called in Audio::process1, now Audio::processMidi is called directly. p4.0.15 Tim.
//void MidiSeq::msgProcess() { msgMsg(MS_PROCESS); }
-void MidiSeq::msgSeek() { msgMsg(SEQM_SEEK); }
-void MidiSeq::msgStop() { msgMsg(MS_STOP); }
+//void MidiSeq::msgSeek() { msgMsg(SEQM_SEEK); } // Removed p4.0.34
+//void MidiSeq::msgStop() { msgMsg(MS_STOP); } //
void MidiSeq::msgSetRtc() { msgMsg(MS_SET_RTC); }
void MidiSeq::msgUpdatePollFd() { msgMsg(MS_UPDATE_POLL_FD); }