kylestetz / lissajous

:musical_note: A tool for programmatic audio performance in the browser using Javascript.
http://lissajousjs.com
MIT License
398 stars 25 forks source link

Ideas for Midi controller input #17

Open kylestetz opened 9 years ago

kylestetz commented 9 years ago

I wanted to get down some notes I had on a possible midi controller API. I would love some feedback!

It would be cool to have a midi object, instantiated via var controller = new midi() (perhaps with some arguments to select the correct controller), and then use its functions the same way generators are used on tracks.

controller = new midi()
t = new track()
t.notes( controller.keys.notes() )
t.beat( controller.keys.beat() )
t.vol( controller.cc(20).map(0,1) )

So that controller.keys has several methods that return events from the keys, such as:

And controller.cc(number) has methods that return events from CC controllers:

My thought on this is that new CC and key values will only be read when a beat is triggered. This is consistent with how Lissajous currently interprets parameter sequences. There are two details of the implementation worth mentioning:

1) schedulers will need to accept event handlers so that controller.keys.beat() can trigger a note, which will be more complicated because they already accept callbacks. This means it might have to be an object that inherits a prototype for the purposes of type checking (if typeof === 'MidiEvent etc).

2) To avoid reading cc values from the midi controller (which would not be possible if you are mapping key values to a parameter) the last value for a given control will need to be cached. This should be really easy to create, simply saving anything that comes in and using that as the data source for the functions passed into parameters.

renaudfv commented 9 years ago

I have started writing down the controller class during the WAC hackaton. I will take this issue in consideration and come back to you asap!

kylestetz commented 9 years ago

Sounds great, can't wait to check it out!