Skip to content

Commit

Permalink
Merge pull request #361 from christofmuc/editBufferProgramNumbers
Browse files Browse the repository at this point in the history
Fix more problems with program numbers extracted and bank numbers being unknown
  • Loading branch information
christofmuc authored Nov 10, 2024
2 parents 75b4b41 + 2e36c05 commit 22a815e
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MidiKraft
3 changes: 2 additions & 1 deletion adaptations/Adaptation Programming Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ Additionally, when you have implement all three functions to enable the ProgramD

def numberFromDump(message)

which will be used if present to detect the original program slot location stored in a program dump for archival purposes.
which will be used if present to detect the original program slot location stored in a program dump for archival purposes. This should return -1 in case
the message is not a program dump (but e.g. an edit buffer dump which has no number stored).

### Requesting a specific program at a specific memory position

Expand Down
2 changes: 0 additions & 2 deletions adaptations/AlesisAndromedaA6.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ def numberFromDump(message):
bank = message[6]
program = message[7]
return bank * numberOfPatchesPerBank() + program
if isEditBufferDump(message):
return 0
raise Exception("Can only extract number from single program dumps")


Expand Down
2 changes: 0 additions & 2 deletions adaptations/BC_Kijimi.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def isDefaultName(patchName):


def numberFromDump(message):
if isEditBufferDump(message):
return 0
if isSingleProgramDump(message):
return message[3] * numberOfPatchesPerBank() + message[4]
raise Exception("Only single program dumps have program numbers")
Expand Down
2 changes: 0 additions & 2 deletions adaptations/Behringer Deepmind 12.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ def nameFromDump(message):
def numberFromDump(message) -> int:
if isSingleProgramDump(message):
return message[8] * numberOfPatchesPerBank() + message[9]
elif isEditBufferDump(message):
return 0
return -1


Expand Down
4 changes: 4 additions & 0 deletions adaptations/GenericEditBufferCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ namespace knobkraft {
try {
auto data = patch->data();
int c = me_->channel().toZeroBasedInt();
if (c < 0) {
c = 0;
spdlog::warn("Channel is unknown in patchToSysex, defaulting to MIDI channel 1");
}
py::object result = me_->callMethod(kConvertToEditBuffer, c, data);
std::vector<uint8> byteData = GenericAdaptation::intVectorToByteVector(result.cast<std::vector<int>>());
return Sysex::vectorToMessages(byteData);
Expand Down
17 changes: 15 additions & 2 deletions adaptations/GenericProgramDumpCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,21 @@ namespace knobkraft {

MidiProgramNumber GenericProgramDumpCapability::getProgramNumber(const std::vector<MidiMessage>& message) const
{
if (!isSingleProgramDump(message)) {
return MidiProgramNumber::invalidProgram();
}
py::gil_scoped_acquire acquire;
if (me_->pythonModuleHasFunction("numberFromDump")) {
try {
auto vector = GenericAdaptation::midiMessagesToVector(message);
py::object result = me_->callMethod(kNumberFromDump, vector);
return MidiProgramNumber::fromZeroBase(result.cast<int>());
int programNumberReturned = result.cast<int>();
if (programNumberReturned >= 0) {
return MidiProgramNumber::fromZeroBase(programNumberReturned);
}
else {
return MidiProgramNumber::invalidProgram();
}
}
catch (py::error_already_set &ex) {
me_->logAdaptationError(kNumberFromDump, ex);
Expand All @@ -117,7 +126,7 @@ namespace knobkraft {
me_->logAdaptationError(kNumberFromDump, ex);
}
}
return MidiProgramNumber::fromZeroBase(0);
return MidiProgramNumber::invalidProgram();
}

std::vector<juce::MidiMessage> GenericProgramDumpCapability::patchToProgramDumpSysex(std::shared_ptr<midikraft::DataFile> patch, MidiProgramNumber programNumber) const
Expand All @@ -127,6 +136,10 @@ namespace knobkraft {
{
auto data = patch->data();
int c = me_->channel().toZeroBasedInt();
if (c < 0) {
spdlog::warn("unknown channel in patchToProgramDumpSysex, defaulting to MIDI channel 1");
c = 0;
}
int programNo = programNumber.toZeroBasedWithBank();
py::object result = me_->callMethod(kConvertToProgramDump, c, data, programNo);
std::vector<uint8> byteData = GenericAdaptation::intVectorToByteVector(result.cast<std::vector<int>>());
Expand Down
2 changes: 1 addition & 1 deletion adaptations/Novation_AStation.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def isSingleProgramDump(message):

def numberFromDump(message):
if not isSingleProgramDump(message):
return 0
return -1
bank = message[11]
bank = bank - 1 if bank > 0 else 0 # some program patch have bank == 0
program = message[12]
Expand Down
2 changes: 1 addition & 1 deletion adaptations/Novation_Summit.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def isSingleProgramDump(message):

def numberFromDump(message):
if not isSingleProgramDump(message):
return 0
return -1
bank = message[12] % 4 # Not more than 4 banks allowed
program = message[13] % 128 # Maximum 128 programs per bank
return bank * 128 + program
Expand Down
2 changes: 1 addition & 1 deletion adaptations/Novation_UltraNova.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def isSingleProgramDump(message):

def numberFromDump(message):
if not isSingleProgramDump(message):
return 0
return -1
bank = message[11]
bank = bank - 1 if bank > 0 else 0 # some program patch have bank == 0
program = message[12]
Expand Down
4 changes: 1 addition & 3 deletions adaptations/YamahaRefaceDX.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ def friendlyProgramName(programNo):


def numberFromDump(message):
if isEditBufferDump(message):
return 0
elif isSingleProgramDump(message):
if isSingleProgramDump(message):
# The program number is in the bulkprogramheader
return message[10]
raise Exception("Can only extract program number from SingleProgramDumps!")
Expand Down
2 changes: 1 addition & 1 deletion adaptations/roland/GenericRoland.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def numberFromDump(self, message) -> int:
model = self.model_from_message(message)
if model is not None:
return model.numberFromDump(message)
return 0
return -1

@knobkraft_api
def nameFromDump(self, message) -> str:
Expand Down
1 change: 0 additions & 1 deletion adaptations/test_BC_Kijimi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_BC_Kijimi():
edit_buffer = convertToEditBuffer(0, patch_from_device_message)
assert isEditBufferDump(edit_buffer)
assert nameFromDump(edit_buffer) == "Kijimi tmp"
assert numberFromDump(edit_buffer) == 0
program_back = convertToProgramDump(0, edit_buffer, 1)
assert isSingleProgramDump(program_back)
assert numberFromDump(program_back) == 1

0 comments on commit 22a815e

Please sign in to comment.