hitsware
Posts: 117
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Write to Amsynth from Basic

Wed May 16, 2018 9:40 pm

Write to Amsynth (or any other) from Basic256 (or any other)

I want to send Midi event messages from (preferably) some dialect of Basic
to Amsynth or Zynaddsubfx or Timidity or ?
What (I think?) I need is an address for the device as if it were a file to be
written to............?????
Thank You, ........ Michael Miller

RichardRussell
Posts: 165
Joined: Thu Jun 21, 2012 10:48 am

Re: Write to Amsynth from Basic

Mon May 21, 2018 11:18 am

hitsware wrote:
Wed May 16, 2018 9:40 pm
I want to send Midi event messages from (preferably) some dialect of Basic to Amsynth or Zynaddsubfx or Timidity or ?
You could use BBC BASIC (BBCSDL) and call the ALSA MIDI API functions - either the raw MIDI or sequencer functions depending on your requirements - using the SYS statement. If you need more details ask again.

Richard.

RichardRussell
Posts: 165
Joined: Thu Jun 21, 2012 10:48 am

Re: Write to Amsynth from Basic

Tue May 22, 2018 2:45 pm

RichardRussell wrote:
Mon May 21, 2018 11:18 am
If you need more details ask again.
You didn't ask, but to check that my advice was sound I have written a trivial raw MIDI output program in BBC BASIC. Before running the program you need to make sure you have a synthesiser running (e.g. amsynth), create a virtual MIDI port to which to output the data, and connect this port to the synth. Typically these commands will do that, but you may need to adapt them if your system defaults to using different ports (check with 'aconnect -l' if necessary):

Code: Select all

amsynth
sudo modprobe snd-virmidi
aconnect 24:0 128:0
Now you can run this BASIC program. It plays just one note, but demonstrates the principle:

Code: Select all

      SND_RAWMIDI_SYNC = 4

      portname$ = "hw:2,0"
      SYS "snd_rawmidi_open", 0, ^midiout%, portname$, SND_RAWMIDI_SYNC TO status%
      IF status% < 0 ERROR 100, "snd_rawmidi_open failed: " + FN_strerror(status%)

      DIM noteon&(2), noteoff&(2)
      noteon&() = &90, 60, 100
      noteoff&() = &90, 60, 0

      SYS "snd_rawmidi_write", midiout%, ^noteon&(0), 3 TO status%
      IF status% < 0 ERROR 100, "snd_rawmidi_write failed: " + FN_strerror(status%)
      WAIT 100
      SYS "snd_rawmidi_write", midiout%, ^noteoff&(0), 3 TO status%
      IF status% < 0 ERROR 100, "snd_rawmidi_write failed: " + FN_strerror(status%)

      SYS "snd_rawmidi_close", midiout%
      END

      DEF FN_strerror(S%)
      LOCAL T%
      SYS "snd_strerror", S% TO T%
      = $$T%

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 6 guests