You are here

midilib for Tcl/Tk

admin의 아바타
첨부 파일파일 크기
Package icon midilib.zip61 KB
Package icon midisrc.zip84.77 KB

출처 : http://home.t-online.de/home/Steffen.Traeger/midi/index.htm

Midilib is a loadable module for Tcl/Tk 8.x on the MS Windows platform. With this addition, Tcl/Tk is capable of receiving and sending MIDI sysex messages from and to external MIDI devices. There is already an existing MIDI library for Tcl/Tk, called tclmidi , but it doesn't support low level access to MIDI devices.

Midilib mainly based on the RPMidi.dll by Bruce James written to support midi devices for his RPEdit, a nice Patch Editor for Guitar Multi-effects Processors. Thanks for doing this great job. I only less modified the code to make it suitable for other applications.
The package consists of C++ code included in a Visual C++ 6.0 project. This means that at present the library only supports Win32 platforms, line Windows 95/98/ME/NT/2000. But I'm looking forward to extend it for Linux.
BTW, MIDI sysex implemenation in Linux is very simple. Write all sysex messages as binary data to /dev/midiXX!

The source code should also be useful to someone wishing to extend Tcl with C language routines.

Command Overview
The MIDI Sysex library contains essentially commands to handle low level MIDI devices and an additionally feature to send short MIDI messages.
Currently supported commands:

midi::getoutdevs
midi::getindevs
midi::openout
midi::openin
midi::sendshort
midi::getoutid
midi::getinid

The midi::openout and midi::openin commands returns a channel id, where the usual tcl channel commands, read, gets, puts, close can then be used.
NOTE:All other MIDI messages, except for System Exclusive, always have 3 or less bytes. The midi::sendshort command can be used to pass such messages, especially to send MIDI note numbers.

Using MIDI sysex commands, you need to first call midi::openout or midi::openin to open some MIDI device for output or input respectively. In order to write out MIDI data to a particular device, you need to first call midi::openout once, passing it the Device ID of that desired device. Get the specific Device ID for your external MIDI device by calling midi::getoutdevs. Then, you can subsequently call a function such as midi::sendshort which (immediately) outputs MIDI data to that device. Or use tcl's channel commands like described above. Don't forget to flush outgoing data using the tcl flush command.

In order to read incoming MIDI data from a particular device, you need to first call midi::openin once, passing it the Device ID of that desired device. Then, Windows will subsequently pass your program each incoming MIDI message from that device. Invoking a "read " your application leeches all data. After you're done inputting or outputting to a device (and have no further use for it), you must close that device. Think of a MIDI device like a file. You open it, you read or write to it, and then you close it.

Installation Instructions
1. If you do not have already installed tcl/tk 8.x, at first you must install it. Get it from the known locations and follow the installation instructions.

2. Download midilib.zip from here.

3. Copy the uncompressed files into your current project directory. Include the following lines into your applikation

lappend auto_path .
package require midi 0.2

4. Ready!
Because it lacks of documention today some examples are given below...

Examples
Here are small examples to show the easily use of the commands.

# get a list of MIDI Output devices 
set mididevs(out) {}
foreach device [midi::getoutdevs] {
    lappend mididevs(out) $device
    puts $device
}
 
# get a list of MIDI Input devices 
set mididevs(in) {}
foreach device [midi::getindevs] {
    lappend mididevs(in) $device
    puts $device
}
 
# get the number of MIDI Output devices 
set num [llength [midi::getoutdevs]]
 
# handle MIDI Output device 
set rc [catch {set id [midi::getoutid]} msg]
if {$rc} {
    set f [midi::openout $id]
} else {
    puts "Fatal error: $msg."
}
fconfigure $f -translation binary
puts -nonewline $f "xf0x41x10x00x02x12xf7"
flush $f
close $f

 
# playing a note number (middle C - 60) for just a second on the default MIDI device 
set f [midi::openout 0]
midi::sendshort 144 60 112
after 1000
midi::sendshort 144 60 0
close $f
  • midisrc.zip: Visual C++ 6.0 source project files and examples
  • midilib.zip: compiled midilib package for Win32