Browse Source

update template

master
Nils 2 years ago
parent
commit
b26cc9eb6e
  1. 11
      template/engine/ly2cbox.py
  2. 8
      template/engine/sampler_sf2.py
  3. 6
      template/qtgui/midiinquickwidget.py

11
template/engine/ly2cbox.py

@ -26,6 +26,7 @@ This is mostly meant for development and testing.
#Standard Library Modules
import re
from typing import Dict
#Third Party Modules
from calfbox import cbox
@ -35,10 +36,10 @@ from . import pitch
from .duration import DB, DL, D1, D2, D4, D8, D16, D32, D64, D128
lyToMidi = {} #filled for all pitches on startup, below
for ly, _pitch in pitch.ly2pitch.items():
lyToMidi:Dict[str,int] = {} #filled for all pitches on startup, below
for lyPitchString, _pitch in pitch.ly2pitch.items():
octOffset = (pitch.octave(_pitch) +1) * 12 #twelve tones per midi octave
lyToMidi[ly] = octOffset + pitch.halfToneDistanceFromC(_pitch)
lyToMidi[lyPitchString] = octOffset + pitch.halfToneDistanceFromC(_pitch)
lyToTicks = {
@ -68,7 +69,7 @@ def pattern(lilypondString:str, channel, velocity:int=100):
"""
Return a cbox pattern
a python byte data type with midi data for cbox.
Channel is 1-16."""
#cbox.Pattern.serialize_event(position, midibyte1 (noteon), midibyte2(pitch), midibyte3(velocity))
channel -= 1
@ -79,7 +80,7 @@ def pattern(lilypondString:str, channel, velocity:int=100):
patternBlob += cbox.Pattern.serialize_event(tickCounter, 0x90+channel, midiPitch, velocity) # note on
patternBlob += cbox.Pattern.serialize_event(endTick, 0x80+channel, midiPitch, velocity) # note off
tickCounter = tickCounter + durationInTicks #no -1 for the next note
pattern = cbox.Document.get_song().pattern_from_blob(patternBlob, tickCounter)
#return patternBlob, startTick
return pattern

8
template/engine/sampler_sf2.py

@ -25,6 +25,8 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
#Python Standard Lib
import os.path
from os import PathLike
from typing import List, Dict, Union
#Third Party
from calfbox import cbox
@ -48,9 +50,9 @@ class Sampler_sf2(Data):
def __init__(self, parentSession, filePath, activePatches, ignoreProgramChanges, mixer:bool, defaultSoundfont=None):
super().__init__(parentSession)
self._unlinkOnSave = []
self._unlinkOnSave:List[Union[str, PathLike]] = [] #old sf2 files no longer in use.
self.filePath = filePath
self.patchlist = {} #bank:{program:name}
self.patchlist:Dict[int,Dict[int, str]] = {} #bank:{program:name}
self.buffer_ignoreProgramChanges = ignoreProgramChanges
self.midiInput = MidiInput(session=parentSession, portName="all")
@ -166,7 +168,7 @@ class Sampler_sf2(Data):
def _convertPatches(self, dictionary:dict):
"""Returns a dict of dicts:
bank:{program:name}"""
result = {}
result:Dict[int,Dict[int, str]] = {} #same as self.patchlist
for value, name in dictionary.items():
program = value & 127
bank = value >> 7

6
template/qtgui/midiinquickwidget.py

@ -74,19 +74,19 @@ class QuickMidiInputComboController(QtWidgets.QWidget):
#api.callbacks.auditionerVolumeChanged.append(self.callback__auditionerVolumeChanged)
def callback_startLoadingAuditionerInstrument(self, idkey):
self.parentWidget.qtApp.setOverrideCursor(QtCore.Qt.WaitCursor) #reset in self.callback_auditionerInstrumentChanged
self.parentWidget.qtApp.setOverrideCursor(QtCore.Qt.WaitCursor) # type: ignore #mypy doesn't know PyQts parent Widget #reset in self.callback_auditionerInstrumentChanged
self.label.setText(QtCore.QCoreApplication.translate("QuickMidiInputComboController", "…loading…"))
self.parentWidget.qtApp.processEvents() #actually show the label and cursor
def callback_auditionerInstrumentChanged(self, exportMetadata:dict):
self.parentWidget.qtApp.restoreOverrideCursor() #We assume the cursor was set to a loading animation
app = self.parentWidget.qtApp.restoreOverrideCursor() # type: ignore #mypy doesn't know PyQts parent Widget #We assume the cursor was set to a loading animation
key = exportMetadata["id-key"]
t = f"➜ [{key[0]}-{key[1]}] {exportMetadata['name']}"
self.label.setText(t)
def callback__auditionerVolumeChanged(self, value:float):
self.volumeDial.setValue(value)
self.parentWidget.statusBar().showMessage(QtCore.QCoreApplication.translate("QuickMidiInputComboController", "Volume: {}").format(value))
self.parentWidget.statusBar().showMessage(QtCore.QCoreApplication.translate("QuickMidiInputComboController", "Volume: {}").format(value)) # type: ignore #mypy doesn't know PyQts parent Widget
def _sendVolumeChangeToEngine(self, newValue):
self.volumeDial.blockSignals(True)

Loading…
Cancel
Save