diff options
author | Florian Jung <flo@windfisch.org> | 2011-06-03 14:24:08 +0000 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2011-06-03 14:24:08 +0000 |
commit | db164b62e3892bd17d1a2eabca76bde3b67072df (patch) | |
tree | ab71ac4b4f05ab94c008d75ef7052bef5af6cc74 /muse2/muse/app.cpp | |
parent | def4fdb391f5207ebbe61881416f39f3d896cc5d (diff) | |
parent | 9187899632c14d64b3fae6477b7f941240f912a6 (diff) |
merged with trunk and adapted new functions
Diffstat (limited to 'muse2/muse/app.cpp')
-rw-r--r-- | muse2/muse/app.cpp | 1089 |
1 files changed, 11 insertions, 1078 deletions
diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index adac840a..72cdad6a 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -43,7 +43,7 @@ #include "mixdowndialog.h" #include "pianoroll.h" #include "scoreedit.h" -#include "popupmenu.h" +#include "routepopup.h" #include "shortcutconfig.h" #include "songinfo.h" #include "ticksynth.h" @@ -93,7 +93,6 @@ static QString* projectList[PROJECT_LIST_LEN]; extern void initMidiSynth(); extern void exitJackAudio(); extern void exitDummyAudio(); -// p3.3.39 extern void exitOSC(); #ifdef HAVE_LASH @@ -809,7 +808,6 @@ MusE::MusE(int argc, char** argv) : QMainWindow() editInstrument = 0; routingPopupMenu = 0; progress = 0; - //routingPopupView = 0; appName = QString("MusE"); setWindowTitle(appName); @@ -1658,7 +1656,6 @@ void MusE::initMidiDevices() audio->msgInitMidiDevices(); - // Added by T356 //audio->msgIdle(false); } @@ -1815,7 +1812,7 @@ void MusE::loadProjectFile1(const QString& name, bool songTemplate, bool loadAll } else { Xml xml(f); - read(xml, !loadAll); + read(xml, !loadAll, songTemplate); bool fileError = ferror(f); popenFlag ? pclose(f) : fclose(f); if (fileError) { @@ -2080,7 +2077,7 @@ bool MusE::save(const QString& name, bool overwriteWarn) if (ferror(f)) { QString s = "Write File\n" + name + "\nfailed: " //+ strerror(errno); - + QString(strerror(errno)); // p4.0.0 + + QString(strerror(errno)); QMessageBox::critical(this, tr("MusE: Write File failed"), s); popenFlag? pclose(f) : fclose(f); @@ -2172,10 +2169,10 @@ void MusE::closeEvent(QCloseEvent* event) printf("MusE: Exiting Metronome\n"); exitMetronome(); - // p3.3.47 - // Make sure to clear the menu, which deletes any sub menus. + // Make sure to delete the menu. ~routingPopupMenu() will NOT be called automatically. + // Even though it is a child of MusE, it just passes MusE onto the underlying PopupMenus. p4.0.26 if(routingPopupMenu) - routingPopupMenu->clear(); + delete routingPopupMenu; #if 0 if(routingPopupView) { @@ -2201,10 +2198,8 @@ void MusE::closeEvent(QCloseEvent* event) d.remove(f.completeBaseName() + ".wca"); } - // Added by Tim. p3.3.14 - #ifdef HAVE_LASH - // Disconnect gracefully from LASH. + // Disconnect gracefully from LASH. Tim. p3.3.14 if(lash_client) { if(debugMsg) @@ -2292,1080 +2287,18 @@ void MusE::showTransport(bool flag) //--------------------------------------------------------- // getRoutingPopupMenu +// Get the special common routing popup menu. Used (so far) +// by audio strip, midi strip, and midi trackinfo. //--------------------------------------------------------- -PopupMenu* MusE::getRoutingPopupMenu() +RoutePopupMenu* MusE::getRoutingPopupMenu() { if(!routingPopupMenu) - routingPopupMenu = new PopupMenu(this); + routingPopupMenu = new RoutePopupMenu(this); return routingPopupMenu; } //--------------------------------------------------------- -// updateRouteMenus -//--------------------------------------------------------- - -void MusE::updateRouteMenus(Track* track, QObject* master) -{ - // NOTE: The purpose of this routine is to make sure the items actually reflect - // the routing status. - // In case for some reason a route could not be added (or removed). - // Then the item will be properly un-checked (or checked) here. - - //if(!track || track != gRoutingPopupMenuMaster || track->type() == Track::AUDIO_AUX) - //if(!track || track->type() == Track::AUDIO_AUX) - if(!track || gRoutingPopupMenuMaster != master) // p3.3.50 - return; - - PopupMenu* pup = getRoutingPopupMenu(); - - if(pup->actions().isEmpty()) - return; - - if(!pup->isVisible()) - return; - - //AudioTrack* t = (AudioTrack*)track; - RouteList* rl = gIsOutRoutingPopupMenu ? track->outRoutes() : track->inRoutes(); - - iRouteMenuMap imm = gRoutingMenuMap.begin(); - for(; imm != gRoutingMenuMap.end(); ++imm) - { - // p3.3.50 Ignore the 'toggle' items. - if(imm->second.type == Route::MIDI_PORT_ROUTE && - //imm->first >= (MIDI_PORTS * MIDI_CHANNELS) && imm->first < (MIDI_PORTS * MIDI_CHANNELS + MIDI_PORTS)) - imm->second.channel == (1 << MIDI_CHANNELS) - 1) // p4.0.14 See if all channels are set, rather than using ID. - continue; - - - // p4.0.14 TODO FIXME Couldn't quite figure out the logic yet. It should be possible (I hope). - // But not really required for now, as per above note. - if(gIsOutRoutingPopupMenu && track->isMidiTrack() && - imm->second.type == Route::TRACK_ROUTE && imm->second.track->type() == Track::AUDIO_INPUT) - return; - #if 0 - printf("imm route:\n"); - imm->second.dump(); - if(track->isMidiTrack()) - { - if(imm->second.type == Route::TRACK_ROUTE && imm->second.track->type() == Track::AUDIO_INPUT) - { - Route &aRoute = imm->second; - int chbit = aRoute.channel; - ///Route bRoute(track, chbit); - ///int mdidx = bRoute.midiPort; - int port = ((MidiTrack*)track)->outPort(); - if(port < 0 || port >= MIDI_PORTS) - continue; - int tchbit = 1 << ((MidiTrack*)track)->outChannel(); - - MidiPort* mp = &midiPorts[port]; - - ///Route bRoute(port, chbit); - - //int chmask = 0; - bool found = false; - RouteList* mprl = gIsOutRoutingPopupMenu ? mp->outRoutes() : mp->inRoutes(); - iRoute ir = mprl->begin(); - for(; ir != mprl->end(); ++ir) - { - printf("mp route:\n"); - ir->dump(); - ///if(aRoute.type == Route::TRACK_ROUTE) // Is the map route a track route? - { - if(ir->type == Route::TRACK_ROUTE && ir->track == aRoute.track) // Is the track route a midi port route? - //&& (ir->channel & chbit) == chbit) - //&& (ir->channel & tchbit)) // Is the exact channel mask bit(s) set? - { - printf("track matches\n"); - if(ir->channel & tchbit) - { - found = true; - printf("found: bit matches\n"); - } - break; - } - } - ///else - ///if(*ir == aRoute) - ///{ - //found = true; - /// break; - ///} - } - //pup->setItemChecked(imm->first, found); - //printf("MusE::updateRouteMenus setItemChecked\n"); - // TODO: MusE-2: Convert this, fastest way is to change the routing map, otherwise this requires a lookup. - //if(pup->isItemChecked(imm->first) != (irl != rl->end())) - // pup->setItemChecked(imm->first, irl != rl->end()); - QAction* act = pup->findActionFromData(imm->first); - //printf("set act checked to:%d\n", ir != mprl->end()); - //if(act && act->isChecked() != (ir != mprl->end())) - // act->setChecked(ir != mprl->end()); - printf("set act checked to:%d\n", found); - if(act && act->isChecked() != found) - act->setChecked(found); - - //return; - } - } - #endif - - //bool found = false; - iRoute irl = rl->begin(); - for(; irl != rl->end(); ++irl) - { - if(imm->second.type == Route::MIDI_PORT_ROUTE) // p3.3.50 Is the map route a midi port route? - { - if(irl->type == Route::MIDI_PORT_ROUTE && irl->midiPort == imm->second.midiPort // Is the track route a midi port route? - && (irl->channel & imm->second.channel) == imm->second.channel) // Is the exact channel mask bit(s) set? - { - //found = true; - break; - } - } - else - if(*irl == imm->second) - { - //found = true; - break; - } - } - //pup->setItemChecked(imm->first, found); - //printf("MusE::updateRouteMenus setItemChecked\n"); - // TODO: MusE-2: Convert this, fastest way is to change the routing map, otherwise this requires a lookup. - //if(pup->isItemChecked(imm->first) != (irl != rl->end())) - // pup->setItemChecked(imm->first, irl != rl->end()); - QAction* act = pup->findActionFromData(imm->first); - if(act && act->isChecked() != (irl != rl->end())) - act->setChecked(irl != rl->end()); - } -} - -//--------------------------------------------------------- -// routingPopupMenuActivated -//--------------------------------------------------------- - -void MusE::routingPopupMenuActivated(Track* track, int n) -{ - //if(!track || (track != gRoutingPopupMenuMaster)) - if(!track) - return; - - if(track->isMidiTrack()) - { - PopupMenu* pup = getRoutingPopupMenu(); - - if(pup->actions().isEmpty()) - return; - - //MidiTrack* t = (MidiTrack*)track; - RouteList* rl = gIsOutRoutingPopupMenu ? track->outRoutes() : track->inRoutes(); - - if(n == -1) - return; - - if(!gIsOutRoutingPopupMenu && n == 0) // p4.0.17 - { - muse->configMidiPorts(); - return; - } - - iRouteMenuMap imm = gRoutingMenuMap.find(n); - if(imm == gRoutingMenuMap.end()) - return; - - // Support Midi Port to Audio Input track routes. p4.0.14 Tim. - if(imm->second.type == Route::TRACK_ROUTE) - { - //if(gIsOutRoutingPopupMenu) // Try to avoid splitting like this. - { - Route &aRoute = imm->second; - int chbit = aRoute.channel; - int port = ((MidiTrack*)track)->outPort(); - if(port < 0 || port >= MIDI_PORTS) - return; - - MidiPort* mp = &midiPorts[port]; - ///MidiDevice* md = mp->device(); - - // This is desirable, but could lead to 'hidden' routes unless we add more support - // such as removing the existing routes when user changes flags. - // So for now, just list all valid ports whether read or write. - ///if(!md) - /// return; - ///if(!(md->rwFlags() & (gIsOutRoutingPopupMenu ? 1 : 2))) - /// return; - - //int channel = ((MidiTrack*)track->outChannel(); - Route bRoute(port, chbit); - - int chmask = 0; - RouteList* mprl = gIsOutRoutingPopupMenu ? mp->outRoutes() : mp->inRoutes(); - iRoute ir = mprl->begin(); - for (; ir != mprl->end(); ++ir) - { - if(ir->type == Route::TRACK_ROUTE && ir->track == aRoute.track) // Is there already a route to this port? - { - chmask = ir->channel; // Grab the channel mask. - break; - } - } - //if (iir != rl->end()) - if ((chmask & chbit) == chbit) // Is the channel's bit(s) set? - { - // disconnect - if(gIsOutRoutingPopupMenu) - audio->msgRemoveRoute(bRoute, aRoute); - else - audio->msgRemoveRoute(aRoute, bRoute); - } - else - { - // connect - if(gIsOutRoutingPopupMenu) - audio->msgAddRoute(bRoute, aRoute); - else - audio->msgAddRoute(aRoute, bRoute); - } - - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - - } - return; - } - - - if(imm->second.type != Route::MIDI_PORT_ROUTE) - return; - Route &aRoute = imm->second; - int chbit = aRoute.channel; - Route bRoute(track, chbit); - int mdidx = aRoute.midiPort; - - MidiPort* mp = &midiPorts[mdidx]; - MidiDevice* md = mp->device(); - //if(!md) // Removed p4.0.17 Allow connections to ports with no device. - // return; - - //if(!(md->rwFlags() & 2)) - //if(!(md->rwFlags() & (gIsOutRoutingPopupMenu ? 1 : 2))) - if(md && !(md->rwFlags() & (gIsOutRoutingPopupMenu ? 1 : 2))) // p4.0.17 - return; - - int chmask = 0; - iRoute iir = rl->begin(); - for (; iir != rl->end(); ++iir) - { - //if(*iir == (dst ? bRoute : aRoute)) - //if(*iir == aRoute) - if(iir->type == Route::MIDI_PORT_ROUTE && iir->midiPort == mdidx) // p3.3.50 Is there already a route to this port? - { - chmask = iir->channel; // p3.3.50 Grab the channel mask. - break; - } - } - //if (iir != rl->end()) - if ((chmask & chbit) == chbit) // p3.3.50 Is the channel's bit(s) set? - { - // disconnect - if(gIsOutRoutingPopupMenu) - audio->msgRemoveRoute(bRoute, aRoute); - else - audio->msgRemoveRoute(aRoute, bRoute); - } - else - { - // connect - if(gIsOutRoutingPopupMenu) - audio->msgAddRoute(bRoute, aRoute); - else - audio->msgAddRoute(aRoute, bRoute); - } - - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - } - else - { - // TODO: Try to move code from AudioStrip::routingPopupMenuActivated into here. - - /* - PopupMenu* pup = getRoutingPopupMenu(); - - printf("MusE::routingPopupMenuActivated audio n:%d count:%d\n", n, pup->count()); - - if(pup->count() == 0) - return; - - AudioTrack* t = (AudioTrack*)track; - RouteList* rl = gIsOutRoutingPopupMenu ? t->outRoutes() : t->inRoutes(); - - //QPoint ppt = QCursor::pos(); - - if(n == -1) - { - //printf("MusE::routingPopupMenuActivated audio n = -1 deleting popup...\n"); - printf("MusE::routingPopupMenuActivated audio n = -1\n"); - ///delete pup; - ///pup = 0; - return; - } - else - //if(n == 0) - //{ - //printf("MusE::routingPopupMenuActivated audio n = 0 = tearOffHandle\n"); - //oR->setDown(false); - // return; - //} - //else - { - if(gIsOutRoutingPopupMenu) - { - QString s(pup->text(n)); - - //printf("AudioStrip::routingPopupMenuActivated audio text:%s\n", s.toLatin1().constData()); - - if(track->type() == Track::AUDIO_OUTPUT) - { - ///delete orpup; - - int chan = n & 0xf; - - //Route srcRoute(t, -1); - //Route srcRoute(t, chan, chans); - //Route srcRoute(t, chan, 1); - Route srcRoute(t, chan); - - //Route dstRoute(s, true, -1); - Route dstRoute(s, true, -1, Route::JACK_ROUTE); - //Route dstRoute(s, true, 0, Route::JACK_ROUTE); - - //srcRoute.channel = dstRoute.channel = chan; - dstRoute.channel = chan; - //dstRoute.channels = 1; - - // check if route src->dst exists: - iRoute irl = rl->begin(); - for (; irl != rl->end(); ++irl) { - if (*irl == dstRoute) - break; - } - if (irl != rl->end()) { - // disconnect if route exists - audio->msgRemoveRoute(srcRoute, dstRoute); - } - else { - // connect if route does not exist - audio->msgAddRoute(srcRoute, dstRoute); - } - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - - // p3.3.47 - //pup->popup(ppt, 0); - - //oR->setDown(false); - return; - - // p3.3.46 - ///goto _redisplay; - } - - iRouteMenuMap imm = gRoutingMenuMap.find(n); - if(imm == gRoutingMenuMap.end()) - { - ///delete orpup; - //oR->setDown(false); // orpup->exec() catches mouse release event - return; - } - - //int chan = n >> 16; - //int chans = (chan >> 15) + 1; // Bit 31 MSB: Mono or stereo. - //chan &= 0xffff; - //int chan = imm->second.channel; - //int chans = imm->second.channels; - - //Route srcRoute(t, -1); - //srcRoute.remoteChannel = chan; - //Route srcRoute(t, chan, chans); - Route srcRoute(t, imm->second.channel, imm->second.channels); - //Route srcRoute(t, imm->second.channel); - srcRoute.remoteChannel = imm->second.remoteChannel; - - //Route dstRoute(s, true, -1); - //Route dstRoute(s, true, -1, Route::TRACK_ROUTE); - Route &dstRoute = imm->second; - - // check if route src->dst exists: - iRoute irl = rl->begin(); - for (; irl != rl->end(); ++irl) { - if (*irl == dstRoute) - break; - } - if (irl != rl->end()) { - // disconnect if route exists - audio->msgRemoveRoute(srcRoute, dstRoute); - } - else { - // connect if route does not exist - audio->msgAddRoute(srcRoute, dstRoute); - } - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - - // p3.3.46 - //oR->setDown(false); - ///goto _redisplay; - - // p3.3.47 - //pup->popup(ppt, 0); - } - else - { - QString s(pup->text(n)); - - if(track->type() == Track::AUDIO_INPUT) - { - ///delete pup; - int chan = n & 0xf; - - Route srcRoute(s, false, -1, Route::JACK_ROUTE); - Route dstRoute(t, chan); - - srcRoute.channel = chan; - - iRoute irl = rl->begin(); - for(; irl != rl->end(); ++irl) - { - if(*irl == srcRoute) - break; - } - if(irl != rl->end()) - // disconnect - audio->msgRemoveRoute(srcRoute, dstRoute); - else - // connect - audio->msgAddRoute(srcRoute, dstRoute); - - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - //iR->setDown(false); // pup->exec() catches mouse release event - return; - - // p3.3.46 - ///goto _redisplay; - } - - iRouteMenuMap imm = gRoutingMenuMap.find(n); - if(imm == gRoutingMenuMap.end()) - { - //delete pup; - //iR->setDown(false); // pup->exec() catches mouse release event - return; - } - - //int chan = n >> 16; - //int chans = (chan >> 15) + 1; // Bit 31 MSB: Mono or stereo. - //chan &= 0xffff; - //int chan = imm->second.channel; - //int chans = imm->second.channels; - - //Route srcRoute(s, false, -1); - //Route srcRoute(s, false, -1, Route::TRACK_ROUTE); - Route &srcRoute = imm->second; - - //Route dstRoute(t, -1); - //Route dstRoute(t, chan, chans); - Route dstRoute(t, imm->second.channel, imm->second.channels); - //Route dstRoute(t, imm->second.channel); - dstRoute.remoteChannel = imm->second.remoteChannel; - - iRoute irl = rl->begin(); - for (; irl != rl->end(); ++irl) { - if (*irl == srcRoute) - break; - } - if (irl != rl->end()) { - // disconnect - audio->msgRemoveRoute(srcRoute, dstRoute); - } - else { - // connect - audio->msgAddRoute(srcRoute, dstRoute); - } - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - - // p3.3.46 - //iR->setDown(false); - ///goto _redisplay; - - - - - } - - } - */ - - } - //else - //{ - //} -} - -//--------------------------------------------------------- -// routingPopupMenuAboutToHide -//--------------------------------------------------------- - -void MusE::routingPopupMenuAboutToHide() -{ - // Hmm, can't do this? Sub-menus stay open with this. Re-arranged, testing... Nope. - //PopupMenu* pup = muse->getRoutingPopupMenu(); - //pup->disconnect(); - //pup->clear(); - - gRoutingMenuMap.clear(); - gRoutingPopupMenuMaster = 0; -} - -//--------------------------------------------------------- -// prepareRoutingPopupMenu -//--------------------------------------------------------- - -PopupMenu* MusE::prepareRoutingPopupMenu(Track* track, bool dst) -{ - if(!track) - return 0; - - if(track->isMidiTrack()) - { - RouteList* rl = dst ? track->outRoutes() : track->inRoutes(); - //Route dst(track, -1); - - PopupMenu* pup = getRoutingPopupMenu(); - pup->disconnect(); - //connect(pup, SIGNAL(activated(int)), SLOT(routingPopupMenuActivated(int))); - //connect(pup, SIGNAL(aboutToHide()), SLOT(routingPopupMenuAboutToHide())); - - pup->clear(); - gRoutingMenuMap.clear(); - - int gid = 0; - QAction* act = 0; - - if(dst) - { - // Support Midi Port to Audio Input track routes. p4.0.14 Tim. - int port = ((MidiTrack*)track)->outPort(); - if(port >= 0 && port < MIDI_PORTS) - { - MidiPort* mp = &midiPorts[port]; - - // p4.0.17 Do not list synth devices! Requiring valid device is desirable, - // but could lead to 'hidden' routes unless we add more support - // such as removing the existing routes when user changes flags. - // So for now, just list all valid ports whether read or write. - if(mp->device() && !mp->device()->isSynti()) - { - RouteList* mprl = mp->outRoutes(); - int chbits = 1 << ((MidiTrack*)track)->outChannel(); - //MidiDevice* md = mp->device(); - //if(!md) - // continue; - - pup->addSeparator(); - pup->addAction(new MenuTitleItem(tr("Soloing chain"), pup)); - PopupMenu* subp = new PopupMenu(pup); - subp->setTitle(tr("Audio returns")); - pup->addMenu(subp); - - InputList* al = song->inputs(); - for (iAudioInput i = al->begin(); i != al->end(); ++i) - { - Track* t = *i; - QString s(t->name()); - - act = subp->addAction(s); - act->setData(gid); - act->setCheckable(true); - - Route r(t, chbits); - - gRoutingMenuMap.insert( pRouteMenuMap(gid, r) ); - - for(iRoute ir = mprl->begin(); ir != mprl->end(); ++ir) - { - if(ir->type == Route::TRACK_ROUTE && ir->track == t && (ir->channel & chbits)) - { - act->setChecked(true); - break; - } - } - ++gid; - } - } - } - } - else - { - // Warn if no devices available. Add an item to open midi config. p4.0.17 - int pi = 0; - for( ; pi < MIDI_PORTS; ++pi) - { - MidiDevice* md = midiPorts[pi].device(); - if(md && !md->isSynti() && (md->rwFlags() & 2)) - break; - } - if(pi == MIDI_PORTS) - { - act = pup->addAction(tr("Warning: No midi input devices!")); - act->setCheckable(false); - act->setData(-1); - pup->addSeparator(); - } - act = pup->addAction(QIcon(*settings_midiport_softsynthsIcon), tr("Open midi config...")); - act->setCheckable(false); - act->setData(gid); - pup->addSeparator(); - ++gid; - - pup->addAction(new MenuTitleItem("Midi input ports", pup)); - - for(int i = 0; i < MIDI_PORTS; ++i) - { - // NOTE: Could possibly list all devices, bypassing ports, but no, let's stick with ports. - MidiPort* mp = &midiPorts[i]; - MidiDevice* md = mp->device(); - //if(!md) - // continue; - - // p4.0.17 Do not list synth devices! - if(md && md->isSynti()) - continue; - - if(md && !(md->rwFlags() & 2)) - continue; - - //printf("MusE::prepareRoutingPopupMenu adding submenu portnum:%d\n", i); - - // MusE-2: Check this - needed with QMenu? Help says no. No - verified, it actually causes double triggers! - //connect(subp, SIGNAL(triggered(QAction*)), pup, SIGNAL(triggered(QAction*))); - //connect(subp, SIGNAL(aboutToHide()), pup, SIGNAL(aboutToHide())); - - int chanmask = 0; - // p3.3.50 To reduce number of routes required, from one per channel to just one containing a channel mask. - // Look for the first route to this midi port. There should always be only a single route for each midi port, now. - iRoute ir = rl->begin(); - for( ; ir != rl->end(); ++ir) - { - if(ir->type == Route::MIDI_PORT_ROUTE && ir->midiPort == i) - { - // We have a route to the midi port. Grab the channel mask. - chanmask = ir->channel; - break; - } - } - // p4.0.17 List ports with no device, but with routes to this track, in the main popup. - if(!md && ir == rl->end()) - continue; - - PopupMenu* subp = new PopupMenu(pup); - subp->setTitle(QString("%1:").arg(i+1) + (md ? md->name() : tr("<none>"))); - - for(int ch = 0; ch < MIDI_CHANNELS; ++ch) - { - act = subp->addAction(QString("Channel %1").arg(ch+1)); - act->setCheckable(true); - act->setData(gid); - - int chbit = 1 << ch; - Route srcRoute(i, chbit); // p3.3.50 In accordance with new channel mask, use the bit position. - - gRoutingMenuMap.insert( pRouteMenuMap(gid, srcRoute) ); - - if(chanmask & chbit) // p3.3.50 Is the channel already set? Show item check mark. - act->setChecked(true); - - ++gid; - } - //gid = MIDI_PORTS * MIDI_CHANNELS + i; // Make sure each 'toggle' item gets a unique id. - act = subp->addAction(tr("Toggle all")); - //act->setCheckable(true); - act->setData(gid); - Route togRoute(i, (1 << MIDI_CHANNELS) - 1); // Set all channel bits. - gRoutingMenuMap.insert( pRouteMenuMap(gid, togRoute) ); - ++gid; - pup->addMenu(subp); - } - - #if 0 - // p4.0.17 List ports with no device and no in routes, in a separate popup. - PopupMenu* morep = new PopupMenu(pup); - morep->setTitle(tr("More...")); - for(int i = 0; i < MIDI_PORTS; ++i) - { - MidiPort* mp = &midiPorts[i]; - if(mp->device()) - continue; - - PopupMenu* subp = new PopupMenu(morep); - subp->setTitle(QString("%1:").arg(i) + tr("<none>")); - - // MusE-2: Check this - needed with QMenu? Help says no. No - verified, it actually causes double triggers! - //connect(subp, SIGNAL(triggered(QAction*)), pup, SIGNAL(triggered(QAction*))); - //connect(subp, SIGNAL(aboutToHide()), pup, SIGNAL(aboutToHide())); - - iRoute ir = rl->begin(); - for( ; ir != rl->end(); ++ir) - { - if(ir->type == Route::MIDI_PORT_ROUTE && ir->midiPort == i) - break; - } - if(ir != rl->end()) - continue; - - for(int ch = 0; ch < MIDI_CHANNELS; ++ch) - { - act = subp->addAction(QString("Channel %1").arg(ch+1)); - act->setCheckable(true); - act->setData(gid); - - int chbit = 1 << ch; - Route srcRoute(i, chbit); // In accordance with new channel mask, use the bit position. - - gRoutingMenuMap.insert( pRouteMenuMap(gid, srcRoute) ); - - //if(chanmask & chbit) // Is the channel already set? Show item check mark. - // act->setChecked(true); - - ++gid; - } - //gid = MIDI_PORTS * MIDI_CHANNELS + i; // Make sure each 'toggle' item gets a unique id. - act = subp->addAction(QString("Toggle all")); - //act->setCheckable(true); - act->setData(gid); - Route togRoute(i, (1 << MIDI_CHANNELS) - 1); // Set all channel bits. - gRoutingMenuMap.insert( pRouteMenuMap(gid, togRoute) ); - ++gid; - morep->addMenu(subp); - } - pup->addMenu(morep); - #endif - - } - - if(pup->actions().isEmpty()) - { - gRoutingPopupMenuMaster = 0; - //pup->clear(); - //pup->disconnect(); - gRoutingMenuMap.clear(); - //oR->setDown(false); - return 0; - } - - gIsOutRoutingPopupMenu = dst; - return pup; - } - - return 0; -} - -#if 0 -//--------------------------------------------------------- -// getRoutingPopupView -//--------------------------------------------------------- - -PopupView* MusE::getRoutingPopupView() -{ - if(!routingPopupView) - //routingPopupView = new PopupView(this); - routingPopupView = new PopupView(); - return routingPopupView; -} - -//--------------------------------------------------------- -// routingPopupViewActivated -//--------------------------------------------------------- - -void MusE::routingPopupViewActivated(Track* track, int n) -{ - //if(!track || (track != gRoutingPopupMenuMaster)) - if(!track) - return; - - if(track->isMidiTrack()) - { - PopupView* pup = getRoutingPopupView(); - - //printf("MusE::routingPopupMenuActivated midi n:%d count:%d\n", n, pup->count()); - - if(pup->model()->rowCount() == 0) - return; - - //MidiTrack* t = (MidiTrack*)track; - RouteList* rl = gIsOutRoutingPopupMenu ? track->outRoutes() : track->inRoutes(); - - if(n == -1) - return; - - iRouteMenuMap imm = gRoutingMenuMap.find(n); - if(imm == gRoutingMenuMap.end()) - return; - if(imm->second.type != Route::MIDI_PORT_ROUTE) - return; - Route &aRoute = imm->second; - int chbit = aRoute.channel; - Route bRoute(track, chbit); - int mdidx = aRoute.midiPort; - - MidiPort* mp = &midiPorts[mdidx]; - MidiDevice* md = mp->device(); - if(!md) - return; - - //if(!(md->rwFlags() & 2)) - if(!(md->rwFlags() & (gIsOutRoutingPopupMenu ? 1 : 2))) - return; - - int chmask = 0; - iRoute iir = rl->begin(); - for (; iir != rl->end(); ++iir) - { - //if(*iir == (dst ? bRoute : aRoute)) - //if(*iir == aRoute) - if(iir->type == Route::MIDI_PORT_ROUTE && iir->midiPort == mdidx) // p3.3.50 Is there already a route to this port? - { - chmask = iir->channel; // p3.3.50 Grab the channel mask. - break; - } - } - //if (iir != rl->end()) - if ((chmask & chbit) == chbit) // p3.3.50 Is the channel's bit(s) set? - { - // disconnect - if(gIsOutRoutingPopupMenu) - audio->msgRemoveRoute(bRoute, aRoute); - else - audio->msgRemoveRoute(aRoute, bRoute); - } - else - { - // connect - if(gIsOutRoutingPopupMenu) - audio->msgAddRoute(bRoute, aRoute); - else - audio->msgAddRoute(aRoute, bRoute); - } - - audio->msgUpdateSoloStates(); - song->update(SC_ROUTE); - } - else - { - // TODO: Try to move code from AudioStrip::routingPopupMenuActivated into here. - } - //else - //{ - //} -} - -//--------------------------------------------------------- -// prepareRoutingPopupView -//--------------------------------------------------------- - -PopupView* MusE::prepareRoutingPopupView(Track* track, bool dst) -{ - if(!track) - return 0; - - //QPoint ppt = QCursor::pos(); - - if(track->isMidiTrack()) - { - - //QPoint ppt = parent->rect().bottomLeft(); - - //if(dst) - //{ - // TODO - - //} - //else - //{ - RouteList* rl = dst ? track->outRoutes() : track->inRoutes(); - //Route dst(track, -1); - - ///QPopupMenu* pup = new QPopupMenu(parent); - - PopupView* pup = getRoutingPopupView(); - pup->disconnect(); - //connect(pup, SIGNAL(activated(int)), SLOT(routingPopupMenuActivated(int))); - //connect(pup, SIGNAL(aboutToHide()), SLOT(routingPopupMenuAboutToHide())); - - ///pup->setCheckable(true); - - int gid = 0; - //int n; - - // Routes can't be re-read until the message sent from msgAddRoute1() - // has had time to be sent and actually affected the routes. - ///_redisplay: - - pup->clear(); - gRoutingMenuMap.clear(); - gid = 0; - - //MidiInPortList* tl = song->midiInPorts(); - //for(iMidiInPort i = tl->begin();i != tl->end(); ++i) - for(int i = 0; i < MIDI_PORTS; ++i) - { - //MidiInPort* track = *i; - // NOTE: Could possibly list all devices, bypassing ports, but no, let's stick with ports. - MidiPort* mp = &midiPorts[i]; - MidiDevice* md = mp->device(); - if(!md) - continue; - - if(!(md->rwFlags() & (dst ? 1 : 2))) - continue; - - //printf("MusE::prepareRoutingPopupMenu adding submenu portnum:%d\n", i); - - //QMenu* m = menu->addMenu(track->name()); - //QPopupMenu* subp = new QPopupMenu(parent); - //PopupMenu* subp = new PopupMenu(this); - QStandardItem* subp = new QStandardItem(QT_TRANSLATE_NOOP("@default", md->name())); -/// connect(subp, SIGNAL(activated(int)), pup, SIGNAL(activated(int))); - //connect(subp, SIGNAL(aboutToHide()), pup, SIGNAL(aboutToHide())); - - int chanmask = 0; - // p3.3.50 To reduce number of routes required, from one per channel to just one containing a channel mask. - // Look for the first route to this midi port. There should always be only a single route for each midi port, now. - for(iRoute ir = rl->begin(); ir != rl->end(); ++ir) - { - if(ir->type == Route::MIDI_PORT_ROUTE && ir->midiPort == i) - { - // We have a route to the midi port. Grab the channel mask. - chanmask = ir->channel; - break; - } - } - - for(int ch = 0; ch < MIDI_CHANNELS; ++ch) - { - //QAction* a = m->addAction(QString("Channel %1").arg(ch+1)); - //subp->insertItem(QT_TRANSLATE_NOOP("@default", QString("Channel %1").arg(ch+1)), i * MIDI_CHANNELS + ch); - gid = i * MIDI_CHANNELS + ch; - - //printf("MusE::prepareRoutingPopupMenu inserting gid:%d\n", gid); - -/// subp->insertItem(QString("Channel %1").arg(ch+1), gid); - QStandardItem* sti = new QStandardItem(QString("Channel %1").arg(ch+1)); - sti->setCheckable(true); - sti->setData(gid); - subp->appendRow(sti); - - //a->setCheckable(true); - //Route src(track, ch, RouteNode::TRACK); - //Route src(md, ch); - //Route r = Route(src, dst); - //a->setData(QVariant::fromValue(r)); - //a->setChecked(rl->indexOf(r) != -1); - - //Route srcRoute(md, ch); - //Route srcRoute(i, ch); // p3.3.49 New: Midi port route. - int chbit = 1 << ch; - Route srcRoute(i, chbit); // p3.3.50 In accordance with new channel mask, use the bit position. - - gRoutingMenuMap.insert( pRouteMenuMap(gid, srcRoute) ); - - //for(iRoute ir = rl->begin(); ir != rl->end(); ++ir) // p3.3.50 Removed. - //{ - //if(*ir == dst) - // if(*ir == srcRoute) - // { - // subp->setItemChecked(id, true); - // break; - // } - //} - if(chanmask & chbit) // p3.3.50 Is the channel already set? Show item check mark. -/// subp->setItemChecked(gid, true); - sti->setCheckState(Qt::Checked); - } - //subp->insertItem(QString("Toggle all"), 1000+i); - // p3.3.50 One route with all channel bits set. - gid = MIDI_PORTS * MIDI_CHANNELS + i; // Make sure each 'toggle' item gets a unique id. -/// subp->insertItem(QString("Toggle all"), gid); - QStandardItem* sti = new QStandardItem(QString("Toggle all")); - sti->setData(gid); - subp->appendRow(sti); - - Route togRoute(i, (1 << MIDI_CHANNELS) - 1); // Set all channel bits. - gRoutingMenuMap.insert( pRouteMenuMap(gid, togRoute) ); - -/// pup->insertItem(QT_TRANSLATE_NOOP("@default", md->name()), subp); - pup->model()->appendRow(subp); - pup->updateView(); - } - - /* - QPopupMenu* pup = new QPopupMenu(iR); - pup->setCheckable(true); - //MidiTrack* t = (MidiTrack*)track; - RouteList* irl = track->inRoutes(); - - MidiTrack* t = (MidiTrack*)track; - int gid = 0; - for (int i = 0; i < channel; ++i) - { - char buffer[128]; - snprintf(buffer, 128, "%s %d", tr("Channel").toLatin1().constData(), i+1); - MenuTitleItem* titel = new MenuTitleItem(QString(buffer)); - pup->insertItem(titel); - - if (!checkAudioDevice()) return; - std::list<QString> ol = audioDevice->outputPorts(); - for (std::list<QString>::iterator ip = ol.begin(); ip != ol.end(); ++ip) { - int id = pup->insertItem(*ip, (gid * 16) + i); - Route dst(*ip, true, i); - ++gid; - for (iRoute ir = irl->begin(); ir != irl->end(); ++ir) { - if (*ir == dst) { - pup->setItemChecked(id, true); - break; - } - } - } - if (i+1 != channel) - pup->addSeparator(); - } - */ - -/// if(pup->count() == 0) - if(pup->model()->rowCount() == 0) - { - ///delete pup; - gRoutingPopupMenuMaster = 0; - //pup->clear(); - //pup->disconnect(); - gRoutingMenuMap.clear(); - //oR->setDown(false); - return 0; - } - - gIsOutRoutingPopupMenu = dst; - return pup; - } - - return 0; -} -#endif - -//--------------------------------------------------------- // saveAs //--------------------------------------------------------- |