MidiShare for schemers


Jacques Herry

35, resid Corlay

22300 Lannion




Doc for mzShare3216 mzscheme extension.This soft is provided for you pleasure but keep in mind I'am a devoted programmer. And perhaps bugs can be live here. You can send need and feedback at : Jacques.herry@wanadoo.fr


it's free under gnu licence as another guy say and all the world know gpl

The grame package have also his artistic licence look @ their site.

This package need the mshare3216Thunk windows, but the C src is for you for further

Compilation on MAC and UNIX

Download the user and developer packages from http://www.grame.fr/MidiShare 

PLT scheme from http://www.cs.rice.edu/CS/PLT/packages/drscheme

** install the two zipped files and read the doc provided by grame **

** before attempt to use this extension. It is a very powerfull package**

** experience is connaissance but without connaissance **

** experience ... ??? hum hum !! => look at the books ***


MidiShare is ported to Mac,Unix,Win,win9x,win2000 by Grame

( and by me also as mzscheme extension - the windows thunk version run I don't have compilator for

MAC and UNIX -)

For the tutorial you can test the lisp tutorial, provided on the grame distribution

with little changes for scheme syntax it work.

I provide a little test and this guide for use.

Perhaps another one can write a better guide for the Scheme world.

English is not my mother language and you can see it is not the academic and I am very

Lazy for writing doc, but I hope this essais is suffisiant.


For the functions utilisation read the official doc in MidiShare developer distribution

Diffs are commented in the list below

And the doc are in MidiShare.pdf as MS ref in Comments col

and thunk release pdf . as TH in Comments col

Scheme Grame Comments
"midi-get-version" MidiGetVersion  MS
"midi-share?" MidiShare  MS
"midi-get-ind-appl" MidiGetIndAppl  MS
"midi-count-appls" MidiCountAppls  MS
"midi-get-named-appl" MidiGetNamedAppl  MS

;;SMPTE struct make-smpte-loc create a new smpte struct for use

;; with the fonctions whiche need this


"smpte-loc-format" "smpte-loc-hours"



6 num args for this constructor are mandatory

(define my-smpte (make-smpte-loc 1 2 3 4 5 6))

The fields are the same as in c and setter + getter procs are here

With the same fields as C struct.You can get the value by first collect
the info :
(define si (midi-get-sync-info))
And now
(sync-info-time si) =>what you want.

(set-sync-info-time! si 20000)


return a scheme struct

sync-info is the key for accessing fields in the struct


Without argument

In scheme I don't provide constructor because this is only a readable value => no arg

"midi-set-sync-mode!" MidiSetSyncMode  MS
"midi-get-ext-time " MidiGetExtTime  MS
"midi-int->ext-time" MidiInt2ExtTime  MS
"midi-ext->int-time" MidiExt2IntTime  MS
"midi-time->smpte" MidiTime2Smpte  MS
"midi-smpte->time" MidiSmpte2Time  MS


;;The fundamentales procs

"midi-open" MidiOpen  MS
"midi-close" MidiClose  MS
"midi-get-name" MidiGetName  MS
"midi-set-name!" MidiSetName  MS
;; filter are implemented as <midi-filter> type
"midi-new-filter" MidiNewFilter TH
"midi-get-filter" MidiGetFilter  TH
"midi-set-filter!" MidiSetFilter  TH
"midi-free-filter" MidiFreeFilter TH Filter becomes <midi-filter-killed> a new type, so you cannot ruse invalid pointer with this securit type
"midi-accept-port" MidiAcceptPort  TH
"midi-accept-chan" MidiAcceptChan  TH
"midi-accept-type" MidiAcceptType  TH



MidiIsAcceptedPort  TH



MidiIsAcceptedChan  TH



MidiIsAcceptedType  TH
"midi-connect" MidiConnect  MS
"midi-is-connected?" MidiIsConnected  MS
"midi-set-port-state!" MidiSetPortState  MS
"midi-get-port-state" MidiGetPortState  MS
"midi-new-cell" MidiNewCell MS => <midi-ev>
"midi-free-cell" MidiFreeCell MS => <midi-ev-killed>
"midi-free-space" MidiFreeSpace  MS
"midi-total-space" MidiTotalSpace  MS
"midi-grow-space" MidiGrowSpace  MS

;; if an event cannot be allocated

;; the event become false

else the <midi-ev> is returned.

;; the ev is not a pointer but an scheme type <midi-ev>

"midi-new-ev" MidiNewEv MS => (define jo (midi-new-ev typeNote)) return <midi-ev> if ok else return #f.
"midi-copy-ev" MidiCopyEv MS return <midi-ev> if ok else return #f.
"midi-free-ev" MidiFreeEv MS => the <midi-ev> become <midi-ev-killed> => no memory corrupted if you want reuse this you can't.
"midi-set-field!" MidiSetField  MS
"midi-get-field" MidiGetField  MS
"midi-add-field" MidiAddField  MS
"midi-count-fields" MidiCountFields  MS
"midi-set-link!" MidiSetLink  TH
"midi-get-link" MidiGetLink  TH returns <midi-ev> if there is an event else return #f.
"midi-set-date" MidiSetDate  TH
"midi-get-date" MidiGetDate  TH
"midi-set-ref-num!" MidiSetRefNum  TH
"midi-get-ref-num" MidiGetRefNum  TH
"midi-set-type!" MidiSetType  TH
"midi-get-type" MidiGetType  TH
"midi-set-chan!" MidiSetChan  TH
"midi-get-chan" MidiGetChan  TH
"midi-set-port!" MidiSetPort  TH
"midi-get-port" MidiGetPort  TH
"midi-set-data0!" MidiSetData0


Look at the MidiShare memory management for comprehension

"midi-get-data0" MidiGetData0  MS
"midi-set-data1!" MidiSetData1  MS
"midi-get-data1" MidiGetData1  MS
"midi-set-data2!" MidiSetData2  MS
"midi-get-data2" MidiGetData2  MS
"midi-set-data3!" MidiSetData3  MS
"midi-get-data3" MidiGetData3  MS
"midi-get-time" MidiGetTime  MS
seq is not a pointer in scheme but <midi-seq> type
"midi-new-seq" MidiNewSeq  MS return <midi-seq> if ok else return #f.
"midi-add-seq" MidiAddSeq  MS
"midi-free-seq" MidiFreeSeq MS => <midi-seq-killed>
"midi-clear-seq" MidiClearSeq MS => <midi-seq> empty
"midi-send-im" MidiSendIm  MS => the <midi-ev> become <midi-ev-killed> => no memory corrupted if you want reuse this you can't.
"midi-send" MidiSend  MS => the <midi-ev> become <midi-ev-killed> => no memory corrupted if you want reuse this you can't.
"midi-send-at" MidiSendAt  MS => the <midi-ev> become <midi-ev-killed> => no memory corrupted if you want reuse this you can't.
"midi-get-first-ev" MidiGetFirstEv  MS returns <midi-ev> if there is an event else return #f.
"midi-get-last-ev" MidiGetLastEv  MS returns <midi-ev> if there is an event else return #f.
"midi-set-first-ev!" MidiSetFirstEv  MS
"midi-set-last-ev!" MidiSetLastEv  MS
"midi-count-evs" MidiCountEvs  MS
"midi-get-ev" MidiGetEv  MS returns <midi-ev> if an event is available else return #f.
"midi-avail-ev" MidiAvailEv  MS returns <midi-ev> if an event is available else return #f.
"midi-flush-evs" MidiFlushEvs  MS


;; here proc for real time not implemented in 3216

;; experimented programmer can implement this in C extension

;; I provide the canevas but I don't know if this can work in mzscheme

;; without system degradation. 3216 is a better implementation

;; than the 32 bit port on windows (Grame src) don't cry ;) but

;; now go to ftp.grame.fr for the windows 2000 implementation download lib and dll

;; and with little perspiration you can implement the good real time 32bits

;; for the mac, unix , windows 2000 and another

;; this procedure are here but don't use for the moment because they can crash mzscheme.

;;it's just a canvas for fix the mind.

Scheme Grame Comments
"midi-rcv-alarm-proc" no is the vector container for the scheme alarm procs

not the same

but look at

MidiSetRcvAlarm for

The spirit

attrib the proc to refNum => (midi-set-rcv-alarm! 1 play)

not the same but look

at MidiGetRcvAlarm

you can see the name of the boxed proc in vector => (midi-get-rcv-alarm 1) => #&#<procedure:play>
"midi-test-rcv-proc" no test the proc ie :=> (midi-test-rcv-proc 1)

No, is replacement for


the alarm is set to zero => no trigger midi ev now