From 081ca27dbf5a9baba1ddf22f73fdb7e7f41e9e07 Mon Sep 17 00:00:00 2001 From: Werner Schweer Date: Mon, 20 Nov 2006 12:09:43 +0000 Subject: updates & fixes --- muse/CMakeLists.txt | 2 +- muse/muse/arranger/arranger.cpp | 5 +-- muse/muse/arranger/tlwidget.cpp | 20 ++++++---- muse/muse/audioinput.cpp | 4 -- muse/muse/driver/alsamidi.cpp | 6 +-- muse/muse/midiinport.cpp | 13 +++++-- muse/muse/midiinport.h | 1 + muse/muse/mixer/mstrip.cpp | 4 +- muse/muse/songtrack.cpp | 84 ++++++++++++++++++++++++++++++----------- muse/muse/track.cpp | 43 +++++++++++++++++++++ muse/muse/track.h | 9 ++++- 11 files changed, 146 insertions(+), 45 deletions(-) diff --git a/muse/CMakeLists.txt b/muse/CMakeLists.txt index 973ccae4..71310187 100644 --- a/muse/CMakeLists.txt +++ b/muse/CMakeLists.txt @@ -34,7 +34,7 @@ set(CMAKE_BUILD_TYPE debug) set(CMAKE_CXX_FLAGS "-Wall -Wextra -Winvalid-pch -fno-exceptions") set(CMAKE_CXX_FLAGS_RELEASE "-O2") -set(CMAKE_CXX_FLAGS_DEBUG "-g") +set(CMAKE_CXX_FLAGS_DEBUG "-g -DQT_DEBUG") set(CMAKE_INCLUDE_CURRENT_DIR TRUE) set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) diff --git a/muse/muse/arranger/arranger.cpp b/muse/muse/arranger/arranger.cpp index 6dedc0bb..6ca0cdda 100644 --- a/muse/muse/arranger/arranger.cpp +++ b/muse/muse/arranger/arranger.cpp @@ -105,8 +105,6 @@ class TLayout : public QLayout { QSize sizeHint() const { return ((QWidget*)parent())->size(); } QLayoutItem *itemAt(int index) const { return itemList.value(index); } QLayoutItem *takeAt(int idx) { - if (idx < 0 || idx >= itemList.size()) - printf("TLayout::takeAt: bad index %d\n", idx); return idx >= 0 && idx < itemList.size() ? itemList.takeAt(idx) : 0; } void clear() { @@ -594,7 +592,8 @@ void Arranger::removeTrack(Track* t) t->subtracks.clear(); if (t == _curTrack) { - setSelectedTrack(song->tracks()->front()); + if (!song->tracks()->isEmpty()) + song->selectTrack(song->tracks()->front()); } updateIndex(); } diff --git a/muse/muse/arranger/tlwidget.cpp b/muse/muse/arranger/tlwidget.cpp index 0bca66d9..409b8c72 100644 --- a/muse/muse/arranger/tlwidget.cpp +++ b/muse/muse/arranger/tlwidget.cpp @@ -114,22 +114,26 @@ void TLWidget::labelPlusClicked() void TLWidget::mousePressEvent(QMouseEvent* ev) { + enum { + CMD_REMOVE_TRACK, CMD_COPY_TRACK, CMD_SHOW_AUDIO_GUI, + CMD_SHOW_MIDI_GUI + }; int button = ev->button(); if (button == Qt::RightButton) { QMenu* menu = new QMenu(this); QAction* a; a = menu->addAction(QIcon(*deleteIcon), tr("Delete Track")); - a->setData(0); + a->setData(CMD_REMOVE_TRACK); if (_track->type() == Track::MIDI || _track->type() == Track::WAVE) { a = menu->addAction(tr("Copy Track")); - a->setData(1); + a->setData(CMD_COPY_TRACK); } if (_track->type() == Track::AUDIO_SOFTSYNTH) { SynthI* s = (SynthI*) _track; if (s->hasGui()) { menu->addSeparator(); a = menu->addAction(tr("Show Gui")); - a->setData(2); + a->setData(CMD_SHOW_AUDIO_GUI); a->setCheckable(true); a->setChecked(s->guiVisible()); } @@ -139,7 +143,7 @@ void TLWidget::mousePressEvent(QMouseEvent* ev) if (s->hasGui()) { menu->addSeparator(); a = menu->addAction(tr("Show Gui")); - a->setData(3); + a->setData(CMD_SHOW_MIDI_GUI); a->setCheckable(true); a->setChecked(s->guiVisible()); } @@ -152,10 +156,10 @@ void TLWidget::mousePressEvent(QMouseEvent* ev) switch (rv) { default: break; - case 0: + case CMD_REMOVE_TRACK: song->removeTrack(_track); break; - case 1: + case CMD_COPY_TRACK: { int idx = song->tracks()->indexOf(_track); if (_track->type() == Track::MIDI) { @@ -170,13 +174,13 @@ void TLWidget::mousePressEvent(QMouseEvent* ev) } } break; - case 2: + case CMD_SHOW_AUDIO_GUI: { SynthI* s = (SynthI*) _track; s->showGui(!s->guiVisible()); } break; - case 3: + case CMD_SHOW_MIDI_GUI: { MidiSynti* s = (MidiSynti*) _track; s->showGui(!s->guiVisible()); diff --git a/muse/muse/audioinput.cpp b/muse/muse/audioinput.cpp index f9630cad..6112d15f 100644 --- a/muse/muse/audioinput.cpp +++ b/muse/muse/audioinput.cpp @@ -125,10 +125,6 @@ void AudioInput::collectInputData() Port port = jackPort(ch); if (!port.isZero()) buffer[ch] = audioDriver->getBuffer(port, segmentSize); - else { - printf("NO JACK PORT\n"); - abort(); - } } } diff --git a/muse/muse/driver/alsamidi.cpp b/muse/muse/driver/alsamidi.cpp index 1df1199b..9b86ac12 100644 --- a/muse/muse/driver/alsamidi.cpp +++ b/muse/muse/driver/alsamidi.cpp @@ -396,7 +396,7 @@ void AlsaMidi::removeConnection(snd_seq_connect_t* ev) // thread. //--------------------------------------------------------- -void AlsaMidi::read(MidiSeq* seq) +void AlsaMidi::read(MidiSeq* /*seq*/) { snd_seq_event_t* ev; for (int i = 0;; ++i) { @@ -683,8 +683,8 @@ void AlsaMidi::updateConnections() RouteNode src(pr.src, -1, RouteNode::MIDIPORT); RouteNode dst(iport); Route r = Route(src, dst); - if (iport->inRoutes()->indexOf(r) == -1) - iport->inRoutes()->push_back(r); + if (!iport->inRouteExists(r)) + iport->addInRoute(r); break; } } diff --git a/muse/muse/midiinport.cpp b/muse/muse/midiinport.cpp index 1035bf14..8ee1f0eb 100644 --- a/muse/muse/midiinport.cpp +++ b/muse/muse/midiinport.cpp @@ -177,11 +177,9 @@ void MidiInPort::eventReceived(snd_seq_event_t* ev) // update midi activity // notify gui of new events // - int hold = config.guiRefresh / 5 + 1; // hold for >= 1/5 sec for (iMidiEvent i = ol.begin(); i != ol.end(); ++i) { - if (i->type() == ME_NOTEON) - activity[i->channel()] += hold; + triggerActivity(i->channel()); song->putEvent(*i); if (recordCount == RECORD_FIFO_SIZE) { printf("MusE: eventReceived(): fifo overflow\n"); @@ -248,3 +246,12 @@ bool MidiInPort::checkActivity(int channel) return activity[channel] != 0; } +//--------------------------------------------------------- +// triggerActivity +//--------------------------------------------------------- + +void MidiInPort::triggerActivity(int channel) + { + activity[channel] = config.guiRefresh / 5 + 1; // hold for >= 1/5 sec + } + diff --git a/muse/muse/midiinport.h b/muse/muse/midiinport.h index 8589cf41..2c718fb6 100644 --- a/muse/muse/midiinport.h +++ b/muse/muse/midiinport.h @@ -57,6 +57,7 @@ class MidiInPort : public MidiTrackBase { void beforeProcess(); void afterProcess(); bool checkActivity(int channel); + void triggerActivity(int channel); }; typedef QList MidiInPortList; diff --git a/muse/muse/mixer/mstrip.cpp b/muse/muse/mixer/mstrip.cpp index 2dd68cd9..2e336d21 100644 --- a/muse/muse/mixer/mstrip.cpp +++ b/muse/muse/mixer/mstrip.cpp @@ -788,7 +788,7 @@ void MidiOutPortStrip::oRouteShow() { QMenu* pup = oR->menu(); pup->clear(); - pup->addSeparator()->setText(tr("MidiDevices")); + pup->addSeparator()->setText(tr("AlsaDevices")); RouteList* orl = track->outRoutes(); // @@ -807,6 +807,7 @@ void MidiOutPortStrip::oRouteShow() // // add JACK midi ports to list // + pup->addSeparator()->setText(tr("JackDevices")); ol = audioDriver->inputPorts(true); foreach (PortName ip, ol) { QAction* oa = pup->addAction(ip.name); @@ -1001,6 +1002,7 @@ void MidiInPortStrip::iRouteShow() // // add JACK midi ports to list // + pup->addSeparator()->setText(tr("JackDevices")); ol = audioDriver->outputPorts(true); foreach (PortName ip, ol) { QAction* action = pup->addAction(ip.name); diff --git a/muse/muse/songtrack.cpp b/muse/muse/songtrack.cpp index e345da0a..bc910222 100644 --- a/muse/muse/songtrack.cpp +++ b/muse/muse/songtrack.cpp @@ -22,6 +22,7 @@ #include "audio.h" #include "midiplugin.h" #include "driver/audiodev.h" +#include "driver/mididev.h" #include "muse.h" //--------------------------------------------------------- @@ -207,31 +208,75 @@ void Song::insertTrack(Track* track, int idx) AudioOutput* ao = 0; if (!ol->empty()) ao = ol->front(); - MidiOutPortList* mol = midiOutPorts(); - MidiOutPort* mo = 0; - if (!mol->empty()) - mo = mol->front(); switch (track->type()) { case Track::TRACK_TYPES: case Track::MIDI_OUT: + { + QList op = midiDriver->outputPorts(false); + if (!op.isEmpty()) { + RouteNode src(track); + RouteNode dst(op.back().port, -1, RouteNode::MIDIPORT); + Route r = Route(src, dst); + track->addOutRoute(r); + } + //TODO: autoconnect to JACK midi ports + } + break; + case Track::MIDI_IN: + { + QList op = midiDriver->inputPorts(true); + if (!op.isEmpty()) { + RouteNode src(op.back().port, -1, RouteNode::MIDIPORT); + RouteNode dst(track); + Route r = Route(src, dst); + track->addInRoute(r); + } + //TODO: autoconnect to JACK midi ports + } + break; + case Track::MIDI_SYNTI: break; case Track::MIDI: // - // connect to all midi inputs, if there is not already - // a route + // connect to first channel of all all midi input ports, + // if there is not already a route // - if (!track->noInRoute()) { + if (track->noInRoute()) { MidiInPortList* mi = midiInPorts(); + RouteNode dst(track); for (iMidiInPort i = mi->begin(); i != mi->end(); ++i) { + RouteNode src(*i, 0, RouteNode::TRACK); + track->addInRoute(Route(src, dst)); + } + } + // + // connect to first free input channel in midi output ports + // + if (track->noOutRoute()) { + MidiOutPortList* mo = midiOutPorts(); + for (iMidiOutPort i = mo->begin(); i != mo->end(); ++i) { + RouteList* rl = (*i)->inRoutes(); for (int ch = 0; ch < MIDI_CHANNELS; ++ch) { - RouteNode src(*i, ch, RouteNode::TRACK); - RouteNode dst(track, -1, RouteNode::TRACK); - Route r = Route(src, dst); - track->inRoutes()->push_back(r); + RouteNode src(track); + RouteNode dst(*i, ch, RouteNode::TRACK); + Route r(src, dst); + bool channelUsed = false; + for (iRoute ir = rl->begin(); ir != rl->end(); ++ir) { + if (ir->dst.channel == ch) { + channelUsed = true; + break; + } + } + if (!channelUsed) { + track->addOutRoute(r); + break; + } } + if (!track->noOutRoute()) + break; } } break; @@ -239,7 +284,7 @@ void Song::insertTrack(Track* track, int idx) case Track::WAVE: case Track::AUDIO_GROUP: if (ao) - track->outRoutes()->push_back(Route(RouteNode(track), RouteNode(ao))); + track->addOutRoute(Route(RouteNode(track), RouteNode(ao))); break; case Track::AUDIO_INPUT: @@ -253,12 +298,10 @@ void Song::insertTrack(Track* track, int idx) RouteNode src(is->port, -1, RouteNode::AUDIOPORT); RouteNode dst(track, ch, RouteNode::TRACK); Route r = Route(src, dst); - track->inRoutes()->push_back(r); + track->addInRoute(r); ++is; } } -// if (ao) -// track->outRoutes()->push_back(Route(ao)); } break; case Track::AUDIO_OUTPUT: @@ -270,7 +313,7 @@ void Song::insertTrack(Track* track, int idx) RouteNode src(track, ch, RouteNode::TRACK); RouteNode dst(is->port, -1, RouteNode::AUDIOPORT); Route r = Route(src, dst); - track->outRoutes()->push_back(r); + track->addOutRoute(r); ++is; } } @@ -377,26 +420,26 @@ void Song::insertTrack2(Track* track) if (track->type() == Track::AUDIO_OUTPUT || track->type() == Track::MIDI_OUT) { foreach(Route r, *(track->inRoutes())) { if (r.src.type != RouteNode::AUXPLUGIN) { - r.src.track->outRoutes()->push_back(r); + r.src.track->addOutRoute(r); } } } else if (track->type() == Track::AUDIO_INPUT || track->type() == Track::MIDI_IN) { foreach(Route r, *(track->outRoutes())) { if (r.dst.type != RouteNode::AUXPLUGIN) { - r.dst.track->inRoutes()->push_back(r); + r.dst.track->addInRoute(r); } } } else { foreach(Route r, *(track->inRoutes())) { if (r.src.type != RouteNode::AUXPLUGIN) { - r.src.track->outRoutes()->push_back(r); + r.src.track->addOutRoute(r); } } foreach(Route r, *(track->outRoutes())) { if (r.dst.type != RouteNode::AUXPLUGIN) { - r.dst.track->inRoutes()->push_back(r); + r.dst.track->addInRoute(r); } } } @@ -415,7 +458,6 @@ void Song::removeTrack(Track* track) removeTrack1(track); audio->msgRemoveTrack(track); removeTrack3(track); - endUndo(SC_TRACK_REMOVED | SC_ROUTE); } diff --git a/muse/muse/track.cpp b/muse/muse/track.cpp index af2b2a3d..150a7e57 100644 --- a/muse/muse/track.cpp +++ b/muse/muse/track.cpp @@ -1046,4 +1046,47 @@ void Track::splitPart(Part* part, int tickpos, Part*& p1, Part*& p2) } } +//--------------------------------------------------------- +// addInRoute +//--------------------------------------------------------- + +void Track::addInRoute(const Route& r) + { + if (_inRoutes.indexOf(r) != -1) { + printf("Track::addInRoute: route already there\n"); + return; + } + _inRoutes.push_back(r); + } + +//--------------------------------------------------------- +// addOutRoute +//--------------------------------------------------------- + +void Track::addOutRoute(const Route& r) + { + if (_outRoutes.indexOf(r) != -1) { + printf("Track::addOutRoute: route already there\n"); + return; + } + _outRoutes.push_back(r); + } + +//--------------------------------------------------------- +// inRouteExists +//--------------------------------------------------------- + +bool Track::inRouteExists(const Route& r) const + { + return _inRoutes.indexOf(r) != -1; + } + +//--------------------------------------------------------- +// outRouteExists +//--------------------------------------------------------- + +bool Track::outRouteExists(const Route& r) const + { + return _outRoutes.indexOf(r) != -1; + } diff --git a/muse/muse/track.h b/muse/muse/track.h index fa21b016..e8e14dfc 100644 --- a/muse/muse/track.h +++ b/muse/muse/track.h @@ -297,12 +297,19 @@ class Track : public QObject { void updateMute() { emit muteChanged(isMute()); } unsigned cpos() const; - // routing + //---------------------------------------------------------- + // routing + //---------------------------------------------------------- + RouteList* inRoutes() { return &_inRoutes; } RouteList* outRoutes() { return &_outRoutes; } bool noInRoute() const { return _inRoutes.empty(); } bool noOutRoute() const { return _outRoutes.empty(); } + void addInRoute(const Route& r); + void addOutRoute(const Route& r); void writeRouting(Xml&) const; + bool inRouteExists(const Route& r) const; + bool outRouteExists(const Route& r) const; Port alsaPort(int channel = 0) const { return _alsaPort[channel]; } Port jackPort(int channel = 0) const { return _jackPort[channel]; } -- cgit v1.2.3