Browse Source

Typehints and variable name clash removal in api

master
Nils 9 months ago
parent
commit
dd9759a99b
  1. 16
      engine/api.py

16
engine/api.py

@ -21,11 +21,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging; logger = logging.getLogger(__name__); logger.info("import")
from typing import Dict
import template.engine.api #we need direct access to the module to inject data in the provided structures. but we also need the functions directly. next line:
from template.engine.api import *
import template.engine.ly2cbox as ly2cbox
#New callbacks
class ClientCallbacks(Callbacks): #inherits from the templates api callbacks
def __init__(self):
@ -36,18 +39,22 @@ from template.engine.api import callbacks
_templateStartEngine = startEngine
def startEngine(nsmClient):
_templateStartEngine(nsmClient)
def startEngine(nsmClient, additionalData:dict={}): # type: ignore
_templateStartEngine(nsmClient, additionalData)
#Populate Channel Activity and Channel Instrument Changes midi callbacks
_registerMidiCallbacks()
playTestSignal.patterns = {channel : ly2cbox.pattern("c'16 g c", channel) for channel in range(1, 17)}
playTestSignals = {channel : ly2cbox.pattern("c'16 g c", channel) for channel in range(1, 17)}
#Send initial Data etc.
logger.info("Sending initial callbacks to GUI")
callbacks._soundfontChanged()
callbacks._ignoreProgramChangesChanged()
logger.info("Fluajho api startEngine complete")
def _registerMidiCallbacks():
"""This needs to be a function to delay execution until we have a session and nsm loaded
our data."""
@ -76,6 +83,7 @@ def _registerMidiCallbacks():
#Sampler
playTestSignals:Dict[int, bytes] = {} #channel:cboxPatternBytes patterns are defined in startEngine because we obviously need to wait for cbox to be ready.
def playTestSignal(channel:int):
"""Channel 1-16
Play a short test chime to verify that sound is working and to see how the instrument sounds"""
@ -83,4 +91,4 @@ def playTestSignal(channel:int):
if channel <1 or channel > 16:
raise ValueError(f"Midi Channel must be between 1 and 16 inclusive. Yours is {channel}")
callbacks._channelActivity(channel)
session.data.midiInput.scene.play_pattern(playTestSignal.patterns[channel], 150.0, id=channel) #If there is already an adhoc pattern with a given non-zero id, stop it and release all the pending notes. Retry until all the notes are released.
session.data.midiInput.scene.play_pattern(playTestSignals[channel], 150.0, id=channel) #If there is already an adhoc pattern with a given non-zero id, stop it and release all the pending notes. Retry until all the notes are released.

Loading…
Cancel
Save