Skip to content

Commit

Permalink
Attempt to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippThoelke committed Jul 12, 2024
1 parent c06d19a commit afd740b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/goofi/nodes/outputs/midiccout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import threading

import mido

from goofi.data import Data, DataType
from goofi.node import Node
from goofi.params import IntParam, StringParam
Expand All @@ -21,6 +19,8 @@ def config_output_slots():
return {"midi_status": DataType.STRING}

def config_params():
import mido

available_ports = mido.get_output_names()
return {
"MIDI": {
Expand All @@ -39,7 +39,12 @@ def send_cc(self, outport, cc_number, value, channel):
# convert cc_number to int
cc_number = int(cc_number)
value = int(value)
outport.send(mido.Message("control_change", control=cc_number, value=value, channel=channel))
outport.send(self.mido.Message("control_change", control=cc_number, value=value, channel=channel))

def setup(self):
import mido

self.mido = mido

def process(self, cc1: Data, cc2: Data, cc3: Data, cc4: Data, cc5: Data):
port_name = self.params.MIDI["port_name"].value
Expand All @@ -54,7 +59,7 @@ def process(self, cc1: Data, cc2: Data, cc3: Data, cc4: Data, cc5: Data):
]
cc_data = [cc1, cc2, cc3, cc4, cc5]

outport = mido.open_output(port_name) if port_name != "goofi" else self.goofi_port
outport = self.mido.open_output(port_name) if port_name != "goofi" else self.goofi_port

alert_on = False
try:
Expand Down
14 changes: 10 additions & 4 deletions src/goofi/nodes/outputs/midiout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import threading
import time

import mido
import numpy as np

from goofi.data import Data, DataType
Expand All @@ -22,6 +21,8 @@ def config_output_slots():
return {"midi_status": DataType.STRING}

def config_params():
import mido

available_ports = mido.get_output_names()
return {
"MIDI": {
Expand All @@ -36,9 +37,14 @@ def config_params():

def play_note(self, outport, n, v, d, channel):
"""Thread function to play a note."""
outport.send(mido.Message("note_on", note=n, velocity=v, channel=channel))
outport.send(self.mido.Message("note_on", note=n, velocity=v, channel=channel))
time.sleep(d)
outport.send(mido.Message("note_off", note=n, velocity=0, channel=channel))
outport.send(self.mido.Message("note_off", note=n, velocity=0, channel=channel))

def setup(self):
import mido

self.mido = mido

def process(self, note: Data, velocity: Data, duration: Data):
if note is None or len(note.data) == 0:
Expand All @@ -65,7 +71,7 @@ def process(self, note: Data, velocity: Data, duration: Data):
channel = self.params.MIDI["channel"].value
play_mode = self.params.MIDI["play_mode"].value

outport = mido.open_output(port_name) # Open the MIDI port once
outport = self.mido.open_output(port_name) # Open the MIDI port once
alert_on = False
try:
if play_mode == "simultaneous":
Expand Down

0 comments on commit afd740b

Please sign in to comment.