[clug] Midi from C (some pygame like api?)

Hal Ashburner hal.ashburner at gmail.com
Tue Jan 22 06:22:58 UTC 2019


I have timidity installed on ubu 18.04
With pygame installed I can do:

➜  [hal at tugboat 16:58 ~]  python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame.midi
>>> pygame.midi.init()
>>> p = pygame.midi.Output(2)
>>> p.set_instrument(40)
>>> p.note_on(64,127)
>>> p.note_off(64,127)
>>>


Between the calls to note_on and note_off I hear a violin playing an 'E'
note sustaining for as long as I'd like. [1][2][3]
Fun!
If you've never done it. Do it. Make some noise! Algo-rave the headphones
until your family tap you on the shoulder and say it's time to stop being
DJ |)34|)-|247 now and see to the garbage and dishes. "Do yourself a
favour..." Like it's 1989 and you're rocking Detroit with Kevin
Saunderson.[4] Or Dusseldorf [5]





I'd like to do just this, again, but from C rather than python for reasons
that may be misguided but they're mine and I'm going with them. (I'd prefer
not C++ for this because C is already in use for the project of which this
is a minor part).



Anyone got a cluebat? I'm not having much luck with libasound-dev examples
or tldp (old) documents trying to open an throw bytes at /dev/snd/seq or
whatever else I'm turning up from search engines and code reading.

I'm not making music (or even trying to), I just want the absolute minimum
to get a sound out using midi for some kind of data sonification
experimental hackery-pokery thing. data in -> transform to midi bytes ->
noise

Cheers,
Hal

[1] instrument 40 is violin
https://www.midi.org/specifications-old/item/gm-level-1-sound-set
[2] note 64 is E
http://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies
[3] 127 is the maximum note "velocity"
[4] https://en.wikipedia.org/wiki/Kevin_Saunderson
[5] https://en.wikipedia.org/wiki/Kraftwerk


More information about the linux mailing list