Bubobubobubobubo / sardine

Python's missing "algorave" module. Live code music with Python using MIDI, OSC and/or SuperCollider.
https://sardine.raphaelforment.fr
GNU General Public License v3.0
201 stars 30 forks source link

MixedPlayers: Hybrid MIDI instruments #187

Closed Bubobubobubobubo closed 1 year ago

Bubobubobubobubo commented 1 year ago

Problem

If you want to control a MIDI instrument, you generally have to control both note informations and control messages (to tweak your parameters). To do so, you currently need to have two separate patterns like so:

Pa * n('0 1 2', p=.5)
Pb * cc(ctrl=20, chan=20, value=5)

This is not encouraging experimentation at all because configuring things that way is slow as hell. It would be much better to be able to create MixedPlayers that can effectively combine multiple MIDI functions in one unified interface. You would be able to give a map of parameters with names and it would function as a regular MIDI instrument:

instrument_map = {
   'cutoff': {'control': 20, 'channel': 0, 'alias': 'cut'},
   'resonance': {'control': 21, 'channel': 0, 'alias': 'res'},
}

my_instrument = MIDIInstrument(
    midi_handler=midi,
    channel=0, 
    instrument_map=instrument_map)
instr = my_instrument

... here define a new player ...

Pa * instr('0 1 2', cut=2, res=1)

Implementation

This specialized player is breaking the current architecture a tiny bit. You need to use two senders at once in a coordinated fashion:

However, it does not look impossible to manage at all as long as you can triage information coming from the pattern initially. One can imagine a send.midi_instrument method that would combine both patterns by distinguishing between keys related to the MIDI note and keys related to the MIDI Control message.

Bubobubobubobubo commented 1 year ago

Implemented by 1eeac52. It is also now documented on the website.