summaryrefslogtreecommitdiffstats
path: root/src/commands/studio/ModifyDeviceMappingCommand.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
commit145364a8af6a1fec06556221e66d4b724a62fc9a (patch)
tree53bd71a544008c518034f208d64c932dc2883f50 /src/commands/studio/ModifyDeviceMappingCommand.cpp
downloadrosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz
rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/commands/studio/ModifyDeviceMappingCommand.cpp')
-rw-r--r--src/commands/studio/ModifyDeviceMappingCommand.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/commands/studio/ModifyDeviceMappingCommand.cpp b/src/commands/studio/ModifyDeviceMappingCommand.cpp
new file mode 100644
index 0000000..6f02d8d
--- /dev/null
+++ b/src/commands/studio/ModifyDeviceMappingCommand.cpp
@@ -0,0 +1,147 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ 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; either version 2 of the
+ License, or (at your option) any later version. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "ModifyDeviceMappingCommand.h"
+
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/Device.h"
+#include "base/Instrument.h"
+#include "base/MidiProgram.h"
+#include "base/Studio.h"
+#include "base/Track.h"
+#include "document/RosegardenGUIDoc.h"
+#include <qstring.h>
+
+
+namespace Rosegarden
+{
+
+ModifyDeviceMappingCommand::ModifyDeviceMappingCommand(
+ RosegardenGUIDoc *doc,
+ DeviceId fromDevice,
+ DeviceId toDevice):
+ KNamedCommand(getGlobalName()),
+ m_composition(&doc->getComposition()),
+ m_studio(&doc->getStudio()),
+ m_fromDevice(fromDevice),
+ m_toDevice(toDevice)
+{}
+
+void
+ModifyDeviceMappingCommand::execute()
+{
+ Composition::trackcontainer &tracks =
+ m_composition->getTracks();
+ Composition::trackcontainer::iterator it = tracks.begin();
+ Instrument *instr = 0;
+ int index = 0;
+
+ for (; it != tracks.end(); it++) {
+ instr = m_studio->getInstrumentById(it->second->getInstrument());
+ if (!instr || !instr->getDevice())
+ continue;
+
+ if (instr->getDevice()->getId() == m_fromDevice) {
+ // if source and target are MIDI
+ if (m_studio->getDevice(m_fromDevice)->getType() ==
+ Device::Midi &&
+ m_studio->getDevice(m_toDevice)->getType() ==
+ Device::Midi) {
+ // Try to match channels on the target device
+ //
+ MidiByte channel = instr->getMidiChannel();
+
+ InstrumentList destList = m_studio->
+ getDevice(m_toDevice)->getPresentationInstruments();
+
+ InstrumentList::iterator dIt = destList.begin();
+
+ for (; dIt != destList.end(); dIt++) {
+ if ((*dIt)->getMidiChannel() == channel) {
+ break;
+ }
+ }
+
+ // Failure to match anything and there's no Instruments
+ // at all in the destination. Skip to next source Instrument.
+ //
+ if (dIt == destList.end() || destList.size() == 0)
+ continue;
+
+
+ RG_DEBUG << " Track " << it->first
+ << ", setting Instrument to "
+ << (*dIt)->getId() << endl;
+
+ // store "to" and "from" values
+ //
+ m_mapping.push_back(
+ std::pair < TrackId,
+ InstrumentId >
+ (it->first,
+ instr->getId()));
+
+ it->second->setInstrument((*dIt)->getId());
+ } else // audio is involved in the mapping - use indexes
+ {
+ // assign by index numbers
+ InstrumentList destList = m_studio->
+ getDevice(m_toDevice)->getPresentationInstruments();
+
+ // skip if we can't match
+ //
+ if (index > (int)(destList.size() - 1))
+ continue;
+
+ m_mapping.push_back(
+ std::pair < TrackId,
+ InstrumentId >
+ (it->first,
+ instr->getId()));
+
+ it->second->setInstrument(destList[index]->getId());
+ }
+
+ index++;
+ }
+ }
+
+}
+
+void
+ModifyDeviceMappingCommand::unexecute()
+{
+ std::vector<std::pair<TrackId, InstrumentId> >
+ ::iterator it = m_mapping.begin();
+ Track *track = 0;
+
+ for (; it != m_mapping.end(); it++) {
+ track = m_composition->getTrackById(it->first);
+ track->setInstrument(it->second);
+ }
+}
+
+}