Skip to content

Commit

Permalink
Move getAvailableInstrument() to Device
Browse files Browse the repository at this point in the history
  • Loading branch information
tedfelix committed Apr 4, 2024
1 parent 2a7141e commit 6171ab4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
40 changes: 40 additions & 0 deletions src/base/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@
*/

#include "Device.h"

#include "base/Controllable.h"
#include "base/MidiDevice.h"
#include "base/SoftSynthDevice.h"
#include "misc/Debug.h"
#include "document/RosegardenDocument.h"
#include "base/Composition.h"


namespace Rosegarden
{


const DeviceId Device::NO_DEVICE = 10000;
const DeviceId Device::ALL_DEVICES = 10001;
// "external controller" port.
const DeviceId Device::EXTERNAL_CONTROLLER = 10002;


Device::~Device()
{
//SEQUENCER_DEBUG << "~Device";
Expand Down Expand Up @@ -69,5 +75,39 @@ Device::sendChannelSetups()
}
}

InstrumentId
Device::getAvailableInstrument() const
{
InstrumentList instruments = getPresentationInstruments();
if (instruments.empty())
return NoInstrument;

const Composition &comp =
RosegardenDocument::currentDocument->getComposition();

// Assume not found.
InstrumentId firstInstrumentID{NoInstrument};

// For each instrument on the device
for (const Instrument *instrument : instruments) {
if (!instrument)
continue;

const InstrumentId instrumentID = instrument->getId();

// If we've not found the first one yet, save it in case we don't
// find anything available.
if (firstInstrumentID == NoInstrument)
firstInstrumentID = instrumentID;

// If this instrumentID is not in use, return it.
if (!comp.hasTrack(instrumentID))
return instrumentID;
}

// Return the first instrumentID for this device.
return firstInstrumentID;
}


}
4 changes: 3 additions & 1 deletion src/base/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ class Device : public XmlExportable
virtual InstrumentList getAllInstruments() const = 0;
/// All Instruments that a user is allowed to select.
/**
* For SoftSynthDevice and AudioDevide, this is the same as
* For SoftSynthDevice and AudioDevice, this is the same as
* getAllInstruments().
*
* For MidiDevice, this is different. It omits the "special" Instruments.
* Any Instrument with an ID less than MidiInstrumentBase is dropped from
* this list. See MidiDevice::generatePresentationList().
*/
virtual InstrumentList getPresentationInstruments() const = 0;
/// Returns an InstrumentId that is not currently on a Track.
InstrumentId getAvailableInstrument() const;

/// Send channel setups to each instrument in the device.
/**
Expand Down
37 changes: 1 addition & 36 deletions src/gui/application/RosegardenMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3800,40 +3800,6 @@ RosegardenMainWindow::slotSplitSelected()
m_view->selectTool(SegmentSplitter::ToolName());
}

// ??? Device member?
static InstrumentId getAvailableInstrument(const Device *device)
{
InstrumentList instruments = device->getPresentationInstruments();
if (instruments.empty())
return NoInstrument;

const Composition &comp =
RosegardenDocument::currentDocument->getComposition();

// Assume not found.
InstrumentId firstInstrumentID{NoInstrument};

// For each instrument on the device
for (const Instrument *instrument : instruments) {
if (!instrument)
continue;

const InstrumentId instrumentID = instrument->getId();

// If we've not found the first one yet, save it in case we don't
// find anything available.
if (firstInstrumentID == NoInstrument)
firstInstrumentID = instrumentID;

// If this instrumentID is not in use, return it.
if (!comp.hasTrack(instrumentID))
return instrumentID;
}

// Return the first instrumentID for this device.
return firstInstrumentID;
}

void
RosegardenMainWindow::slotAddTrack()
{
Expand Down Expand Up @@ -3863,8 +3829,7 @@ RosegardenMainWindow::slotAddTrack()
continue;

// Find an Instrument we can use.

foundInstrumentID = getAvailableInstrument(device);
foundInstrumentID = device->getAvailableInstrument();

if (foundInstrumentID != NoInstrument)
break;
Expand Down

0 comments on commit 6171ab4

Please sign in to comment.