From c1cff6358db061239b25f9f5b323822c5b34a9a7 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sun, 23 Jan 2022 12:38:09 +0100 Subject: [PATCH] update template --- template/calfbox/py/nullbox.py | 1 - template/calfbox/sampler.c | 6 ++---- template/calfbox/sampler_api_example2.py | 6 ++++++ template/engine/pitch.py | 27 +++++++++++++++++++++--- template/qtgui/helper.py | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/template/calfbox/py/nullbox.py b/template/calfbox/py/nullbox.py index 246804d..f389766 100644 --- a/template/calfbox/py/nullbox.py +++ b/template/calfbox/py/nullbox.py @@ -58,4 +58,3 @@ sys.modules["calfbox"] = sys.modules["calfbox.nullbox"] import calfbox cbox = NullCalfbox("fake cbox null client") - diff --git a/template/calfbox/sampler.c b/template/calfbox/sampler.c index fb6d4c3..deb94c7 100644 --- a/template/calfbox/sampler.c +++ b/template/calfbox/sampler.c @@ -344,12 +344,10 @@ static gboolean load_program_at(struct sampler_module *m, const char *cfg_sectio return FALSE; if (index != -1) - { swap_program(m, index, pgm, TRUE); - return TRUE; - } + else + sampler_register_program(m, pgm); - sampler_register_program(m, pgm); if (ppgm) *ppgm = pgm; return TRUE; diff --git a/template/calfbox/sampler_api_example2.py b/template/calfbox/sampler_api_example2.py index a7b7ed7..8ea328e 100644 --- a/template/calfbox/sampler_api_example2.py +++ b/template/calfbox/sampler_api_example2.py @@ -14,6 +14,12 @@ scene.clear() instrument = scene.add_new_instrument_layer("test_sampler", "sampler").get_instrument() pgm_no = instrument.engine.get_unused_program() pgm = instrument.engine.load_patch_from_file(pgm_no, 'synthbass.sfz', 'SynthBass') + +# This is not needed, it's here to test for a bug where reloading a program at +# the same slot didn't return the newly loaded program object. +pgm = instrument.engine.load_patch_from_file(pgm_no, 'synthbass.sfz', 'SynthBass') +assert pgm + instrument.engine.set_patch(1, pgm_no) print (instrument.engine.get_patches()) print (instrument.get_output_slot(0)) diff --git a/template/engine/pitch.py b/template/engine/pitch.py index cc94e96..352bf25 100644 --- a/template/engine/pitch.py +++ b/template/engine/pitch.py @@ -1094,6 +1094,30 @@ for _midipitch in range(128): _octave, _pitch = divmod(_midipitch, 12) midi_notenames_german.append("{}{}".format("C Des D Es E F Fis G As A B H".split()[_pitch] ,_octave-1)) + +#midi and sfz note names are normal midi notes again, but this time we need a dict because both Eb and D# are in there. c4 is middle. +_alt = { + "db" : "c#", + "eb" : "d#", + "f#" : "gb", + "ab" : "g#", + "bb" : "a#", +} +midiName2midiPitch = {} +for _midipitch in range(128): #0-127 incl. + _octave, _pitch = divmod(_midipitch, 12) + _octave -= 1 + notename = "c db d eb e f f# g ab a bb b".split()[_pitch] + sfz_name1 = "{}{}".format(notename ,_octave) + midiName2midiPitch[sfz_name1] = _midipitch + if notename in ("db", "eb", "f#", "ab", "bb"): #Add the other variant + sfz_name2 = "{}{}".format(_alt[notename] ,_octave) + midiName2midiPitch[sfz_name2] = _midipitch + +assert midiName2midiPitch["db4"] == 61, midiName2midiPitch["db4"] +assert midiName2midiPitch["db4"] == midiName2midiPitch["c#4"], midiName2midiPitch["c#4"] + + """midi_notenames_lilypond = [] for _midipitch in range(128): _octave, _pitch = divmod(_midipitch, 12) @@ -1176,6 +1200,3 @@ simpleNoteNames["German"] = midi_notenames_german simpleNoteNames["English"] = midi_notenames_english simpleNoteNames["Lilypond"] = midi_notenames_lilypond simpleNoteNames["Drums GM"] = midi_notenames_gm_drums - - - diff --git a/template/qtgui/helper.py b/template/qtgui/helper.py index 2feef0d..af304de 100644 --- a/template/qtgui/helper.py +++ b/template/qtgui/helper.py @@ -314,7 +314,7 @@ class ToggleSwitch(QtWidgets.QAbstractButton): p.setPen(text_color) p.setOpacity(text_opacity) font = p.font() - font.setPixelSize(1.5 * self._thumb_radius) + font.setPixelSize(int(1.5 * self._thumb_radius)) p.setFont(font) p.drawText( QtCore.QRectF(