Skip to content

Commit

Permalink
Check for instrument type change before releasing current instrument (#…
Browse files Browse the repository at this point in the history
…359)

* check for actual instrument type change before releasing current instrument
* remove some unused macro instrument code
  • Loading branch information
maks authored Feb 5, 2025
1 parent bc500ba commit 7a5fbd5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
12 changes: 9 additions & 3 deletions sources/Application/Instruments/I_Instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

#include "Application/Player/TablePlayback.h"

enum InstrumentType { IT_NONE, IT_SAMPLE, IT_MIDI, IT_SID, IT_OPAL, IT_MACRO };
static const char *InstrumentTypeNames[] = {
"NONE", "SAMPLE", "MIDI", "SID", "OPAL", "MACRO",
enum InstrumentType {
IT_NONE = 0,
IT_SAMPLE,
IT_MIDI,
IT_SID,
IT_OPAL,
IT_LAST
};
static const char *InstrumentTypeNames[IT_LAST] = {"NONE", "SAMPLE", "MIDI",
"SID", "OPAL"};

class I_Instrument : public VariableContainer, public Observable {
public:
Expand Down
13 changes: 0 additions & 13 deletions sources/Application/Instruments/InstrumentBank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,6 @@ unsigned short InstrumentBank::GetNextAndAssignID(InstrumentType type,
instruments_[id] = oi;
return id;
} break;
case IT_MACRO: {
MacroInstrument *mi = macroInstrumentPool_.create();
// TODO check for pool exhastion AND show user UI message about it!!!
if (mi == nullptr) {
Trace::Error("Macro INSTRUMENT EXHAUSTED!!!!!!");
}
mi->Init();
instruments_[id] = mi;
return id;
} break;
case IT_NONE:
instruments_[id] = &none_;
return id;
Expand All @@ -245,9 +235,6 @@ void InstrumentBank::releaseInstrument(unsigned short id) {
case IT_OPAL:
opalInstrumentPool_.destroy(instrument);
break;
case IT_MACRO:
macroInstrumentPool_.destroy(instrument);
break;
case IT_NONE:
// NA: None is a "singleton" so no need to release from pool
// BUT it can be assigned to any number of slots
Expand Down
3 changes: 2 additions & 1 deletion sources/Application/Instruments/MacroInstrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class MacroInstrument : public I_Instrument, I_Observer {
virtual bool IsInitialized();
virtual bool IsEmpty();

virtual InstrumentType GetType() { return IT_MACRO; };
// TODO: set a real instrument type before shipping macro instruments
virtual InstrumentType GetType() { return IT_NONE; };
virtual etl::string<24> GetName(); // returns sample name until real
// namer is implemented
virtual void ProcessCommand(int channel, FourCC cc, ushort value);
Expand Down
28 changes: 16 additions & 12 deletions sources/Application/Views/InstrumentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ static void ChangeInstrumentTypeCallback(View &v, ModalView &dialog) {
};

InstrumentView::InstrumentView(GUIWindow &w, ViewData *data)
: FieldView(w, data),
instrumentType_(FourCC::VarInstrumentType, InstrumentTypeNames, 5, 0) {
: FieldView(w, data), instrumentType_(FourCC::VarInstrumentType,
InstrumentTypeNames, IT_LAST, 0) {

project_ = data->project_;

GUIPoint position = GetAnchor();
position._y -= 2;
typeIntVarField_.emplace_back(position, *&instrumentType_, "Type: %s", 0, 4,
1, 1);
typeIntVarField_.emplace_back(position, *&instrumentType_, "Type: %s", 0,
IT_LAST - 1, 1, 1);
fieldList_.insert(fieldList_.end(), &(*typeIntVarField_.rbegin()));
(*typeIntVarField_.rbegin()).AddObserver(*this);
lastFocusID_ = FourCC::VarInstrumentType;
Expand All @@ -59,6 +59,12 @@ void InstrumentView::onInstrumentTypeChange() {
auto id = viewData_->currentInstrumentID_;
// release prev instrument back to available pool
if (old != nullptr) {
// first check if the instrument type actually changed, because could be
// user is at end of instrument list and just keeps pressing key combo to
// trigger next instrument event again and again
if (old->GetType() == nuType) {
return;
}
bank->releaseInstrument(viewData_->currentInstrumentID_);
}

Expand Down Expand Up @@ -117,9 +123,6 @@ void InstrumentView::refreshInstrumentFields(const I_Instrument *old) {
case IT_NONE:
fillNoneParameters();
break;
case IT_MACRO:
fillMacroParameters();
break;
case IT_MIDI:
fillMidiParameters();
break;
Expand All @@ -132,6 +135,9 @@ void InstrumentView::refreshInstrumentFields(const I_Instrument *old) {
case IT_OPAL:
fillOpalParameters();
break;
case IT_LAST:
// NA
break;
};

for (auto field : fieldList_) {
Expand Down Expand Up @@ -665,7 +671,7 @@ void InstrumentView::ProcessButtonMask(unsigned short mask, bool pressed) {

FieldView::ProcessButtonMask(mask);

// B Modifier
// EDIT Modifier
if (mask & EPBM_EDIT) {
if (mask & EPBM_LEFT)
warpToNext(-1);
Expand Down Expand Up @@ -703,8 +709,7 @@ void InstrumentView::ProcessButtonMask(unsigned short mask, bool pressed) {
};
} else {

// A modifier

// ENTER modifier
if (mask == EPBM_ENTER) {
FourCC varID = ((UIIntVarField *)GetFocus())->GetVariableID();
if ((varID == FourCC::SampleInstrumentTable) ||
Expand All @@ -714,8 +719,7 @@ void InstrumentView::ProcessButtonMask(unsigned short mask, bool pressed) {
};
} else {

// R Modifier

// NAV Modifier
if (mask & EPBM_NAV) {
if (mask & EPBM_LEFT) {
ViewType vt = VT_PHRASE;
Expand Down

0 comments on commit 7a5fbd5

Please sign in to comment.