[CM] Using MidiShare with CM and Linux: A brief tutorial

Dave Phillips dlphillips@woh.rr.com
Mon, 28 Mar 2005 09:40:34 -0500


Greetings:

  I've been experimenting with CM's use of GRAME's MidiShare interface 
and I thought I'd share my successes with anyone else on the list who 
might want to explore this aspect of CM a bit further.

  First, it seems that there are problems building MidiShare on some 
distros, notably the current AGNULA/Demudi distro but possibly others. I 
can successfully build and install MidiShare from CVS on a Planet CCRMA 
RH9 system with GCC 3.2.2. I suspect there may be compiler and kernel 
incompatibilities that await being addressed by the MidiShare 
developers. My apologies, I can't directly help anyone having such 
troubles, but I do suggest that you write to the developers for a patch 
to update the sources.

  After building and installing the MidiShare system you'll probably 
need to manually install the driver module. This command does the trick:

    modprobe MidiShare

  If it fails you may have a module installation problem. Review your 
build and installation steps, and make sure the MidiShare.o module is 
present in /lib/modules/your-kernel-here/misc (or similar path). If you 
continue to have problems contact the MidiShare developers.

  MidiShare includes a number of helpful GUI and command-line 
components, including a graphic patch bay for connecting MidiShare 
sources, apps, and targets. Start the msConnect patch bay with this command:

    msconnect

  You should see entries only for MidiShare (0) and msconnect (1).

  Now launch CM in your usual fashion. If the MidiShare module has been 
correctly installed you should see a check mark by the MidiShare name on 
the Systems tab in the cmio GUI (btw, the Load button doesn't seem to 
work for loading MidiShare). However, by itself the presence of the 
module does nothing. You must open a MidiShare port by either clicking 
on the port Open button on the MidiShare tab or issue this command at 
the Lisp prompt:

    (midi-open)

You can close the port by clicking the Close button or by issuing this 
command:

    (midi-close)

  When you open a MidiShare port you should see an instance of "Common 
Music" appear in the msConnect GUI. If you don't see it you may need to 
check whether you've correctly installed MidiShare. See the MidiShare 
documentation for more information regarding its configuration and 
troubleshooting procedures.

  You can query CM for an opened port by issuing the (midi-open?) 
command, but it has caused problems for me with subsequent calls to 
(midi-open). That bug may be fixed by now. You can also ask CM for the 
ID of its MidiShare port with this command from the Lisp prompt (without 
parentheses!) :

    *mp*

  It should return the same slot number for Common Music as seen in the 
msConnect panel.

  Now start an instance of fluidsynth with the following options:

    fluidsynth --midi-driver=midishare --audio-driver=alsa -C0 -R0 -g3 
/home/dlphilp/soundfonts/8mbgmsfx.sf2

  Of course you'll want to substitute your own path and soundfont. The C 
and R options turn off chorus and reverb, the g option sets the gain 
(it's too low by default, IMO). The MIDI and audio driver selections 
should be obvious. The msConnect GUI should now include an entry for 
fluidsynth. If you have problems with fluidsynth, see the fluidsynth 
documentation for more information regarding fluidsynth's options and 
realtime performance controls. Btw, typing 'man fluidsynth' in an xterm 
or at the console prompt will open the very informative fluidsynth 
manual page.

  Return to the msConnect GUI and connect the Common Music entry in the 
Applications column to the fluidsynth entry in the Destinations column. 
At this point you're ready to run some MidiShare-capable code. Try the 
following simple example as a test:

(define (ms-test1)
(process repeat 200
  output (new midi :time (now)
                   :duration (pick .1 .2 .3 .2 .1 .1 .2 .3 .2 .1)
                   :amplitude (between 40 60)
                   :keynum (pick 58 60 62 64 65 67 68 70 72 73 75 76 79 80))
  wait (pick .1 .2)))

(define (ms-test2)
(process repeat 200
  output (new midi :time (now)
                   :duration (pick .1 .2 .3 .2 .1 .1 .2 .3 .2 .1)
                   :amplitude (between 40 60)
                   :keynum (pick 36 38 41 43 48 50 53 55 60 62 65 67 70 72))
  wait (pick .1 .2)))

;;; (events (list (ms-test1) (ms-test2)) "midi.port")


  To run this example from the GUI, simply save it as a file (e.g. 
ms-test.cm) and load it either via the CM Lisp prompt or the cmio 
interface. If you are not using the GUI just enter the events line at 
the prompt. For the GUI just put this line in the Events entry dialog:

    (list (ms-test1) (ms-test2))

For some reason the action will replace the filename in the Execute 
entry box (i.e. "ms-test.cm") with "midi.port". This is a bug, but it's 
a helpful one: if it doesn't appear then you'll know that there's 
something wrong with your code or system setup.

  If all the parts are correctly in place you should hear the process 
begin immediately.

  Please note that this process applies *only* to the CM's high-level 
MIDI objects. The low-level objects are not currently usable in such 
processes under Linux, although you can test the examples from the MIDI 
topic page by entering them at the prompt. Note that some examples will 
not work as expected, but in fact the low-level objects are not 
particularly necessary if you have no need for MidiShare's more 
specialized services.

  Improvements I'd like to see include a start/stop/pause/continue 
control for realtime playback and some further explication regarding the 
MidiShare MIDI file player (as seen in the cmio MidiShare tab). In other 
respects this system appears to be working well under Linux and is a 
valuable addition to CM's output targets.

  Feel free to notify me of any corrections to this brief tutorial. I 
also welcome any other examples that show off CM's MidiShare support.

  Rick: Btw, did CM at one time support Cmix as an output target ? If 
so, is there any chance that it could be revived for RTCmix someday ?

Best,

dp