First time here? Check out the FAQ!
x

best way to send midi data to Kyma from python (&OSC?)

0 votes
471 views

Hi all. 

i'm trying send midi data from a python script to Kyma to trigger 2 KBD samplers.

 

I'm currently sending over osc but there seems to be a couple of problems:

1) latency (the delay is roughly 0.25 seconds)

2) midi channel number seems to be ignored.

I am currently sending osc data as  /key, [channel, on/off,  note, velocity, timbre] e.g. /key, [1, -1, 62, 0.8, 0.8]. with "port = 8000 ip = "169.254.84.113"

At the Kyma end, the osc is being logged and mapped. In the image I have 2 samplers 1 for piano (source MIDIInput, channel 1), and bass (source MIDIInput, channel 2), each with a different midiVoice set to independent channel. However, when i send it osc for each channel only the piano channel (1) is played.

 

Questions:

1) Why the latency? How to improve? Should I send raw midi data over OSC?

2) Why the midi channels are not being considered and routed to the specific MidiVoice

 

TIA

Craig

 

asked Jan 10 in Controllers, OSC & MIDI by craigvear (150 points)
Interestingly, I tested the midi message from Python through OSC with the following results:
- midi message logged and parsed
- no sound
- same latency

Message format: /my_midi, [0x90, 0x3D, 0x78] - which I believe should be a note on for channel 0, midinote 61, velocity 120.
Could you modify your message above to include a leading zero byte (ignored source port byte) and make sure the OSC message type is m?

For example:
   /my_midi,m [0x00, 0x90, 0x3D, 0x78]
Thanks - still no sound I'm afraid.
It's being logged and parsed in the Event Log: my_midi,m,iiii 0 144 61 120.

If I change the channel to 0x91, still no response.
Or if I return to /<any_name>,m, iii (3 arguments) - no response

I've checked with the fake keyboard and midi channels are separated between the 2 instruments (piano and bass).

bw c
To replicate this issue here is my setup and code:

Paca plugged into Mac using single Ethernet cable into port B
Kyma 7 (latest) running Kyma Sound Library/ Sample-based/ Sample KBD*.kym/ Piano & Percussion like/ KBD-10 Keymapped Multisample Piano

Python code:

from pythonosc import udp_client
from time import sleep

port = 8000
ip = "169.254.238.18"  # Kyma IP addr

client = udp_client.SimpleUDPClient(ip, port)

for x in range(10):
    addr = "/my_midi,m"
    midi_msg = [0x00, 0x92, 0x3D, 0x78]

    print(f"sending message: {addr}, {midi_msg}")
    client.send_message(addr, midi_msg)
    sleep(0.5)

1 Answer

0 votes

It appears that python-osc expects length-4 tuples to specify a MIDI message. Tuples should be enclosed in parentheses rather than square brackets and the entries of the tuple are:

( port_id, status_byte, data1, data2 )

When sending short messages to the Pacamara/rana, fill the empty slots with 0xFF.

For your example, try the following Python code (you may need to add note off messages for this to work properly):

from pythonosc import udp_client
from time import sleep

port = 8000
ip = "169.254.238.18"  # Kyma IP addr

client = udp_client.SimpleUDPClient(ip, port)

for x in range(10):
    addr = "/my_midi"
    midi_msg = (0x00, 0x92, 0x3D, 0x78)

    print(f"sending message: {addr}, {midi_msg}")
    client.send_message(addr, midi_msg)
    sleep(0.5)

answered Jan 12 by ssc (Savant) (128,120 points)
Thank K&C for helping me with this. Still no success. Perhaps I need to take a different tack with the problem.

I can get the KBD sampler to play using /key, but cant assign midi channel (they all default to 1 e.g. /key, [2, -1, x+52.0, x/10, x/10] = piano on channel 1 (when I expect it to be bass on channel 2)

MIDI across OSC is parsed on the logger, but as /my_midi/m,iiii. even sending raw binary (e.g. b'\x91\x3D\x78\xFF') get mapped on the logger, as /my_midi,m,b

Whats the best way to stream midi data to Paca over through OSC using the Cat cable? Is there a proven instance of it working with another language?

Much love to you both
c
(Oh and HNY!!!!)
YEAH!!!! Nailed it :) (big thanks to Carla, Kurt, and Doug).

The problem that I had was (as Doug pointed out) the library wasnt parsing 'm' type messages. So I looked for another library that a) accepted 'm' types and b) allowed me to declare them in the message.

I found osc4py3 which worked and made a single piano note (oh did I dance in joy!!).

Here is the code:


from time import sleep
from osc4py3.as_eventloop import *
from osc4py3.oscbuildparse import *

# declare Kyma address and port
port = 8000
ip = "169.254.91.128"

# startup the OSC client
osc_startup()

# make a channel especially for Kyma
osc_udp_client(ip, port, "kyma")

# send note on (can be sent as decimal)
# build message
on_msg = OSCMessage("/my_midi", ",m", [OSCmidi(0, 144, 72, 64)])
print(f"sending {on_msg}")

# put it in the chamber
osc_send(on_msg, "kyma")

# send it off
osc_process()

sleep(1)

# send note off (can be sent as Hex)
off_msg = OSCMessage("/my_midi", ",m", [OSCmidi(0x00, 0x80, 0x48, 0x40)])
print(f"sending {off_msg}")

# put it in the chamber
osc_send(off_msg, "kyma")

# send it off
osc_process()

# terminate the process
osc_terminate()
...