midistreamdll

This is a wrapper for the Windows Midi stream API.

News

Examples

Midi file sequencer

In the examples directory in the zips, you'll find seq.tcl, a midi file sequencer. This example uses the tclMIDI package to read Midi files.

package require midi
package require midistreamdll

# Create a midi stream header, this header will be used to send event to the
# sequencer.
set h [midistreamdll::header]

# Load the midi file specified on the command line
set mf [midi::file]
$mf read [lindex $argv 0]

# Add events to header, skip SysEx and non-tempo Meta events
set cnt 0
foreach te [$mf flatten -no_sys_ex 1 -include_meta {tempo}] {
    $h add event {*}$te
    incr cnt
}

puts "Streamed $cnt event"

# Open a midi stream device
set s [midistreamdll::open 0]

# Set the ticks per beat
if {[$mf cget -time_division_type] eq "ticks_per_beat"} {
    $s set timediv [$mf cget -ticks_per_beat]
}

# Send header to the device
$s out $h

# Sequence the events
$s play

# Wait until header is released by the sequencer
while 1 {
    if {![catch {$h destroy}]} {
        break
    }
    puts "@ [$s position]"
    after 1000
}

# Cleanup
$s close
$mf destroy

exit

Drum machine

In the examples directory in the zips, you'll find drums.tcl, a little drum machine.

WikiDbImage drums.png

AMG: The user interface looks a bit like the screenshot I have posted on Possible Grid Enhancements, except that mine is all screwed up. :^)

Questions / remarks

  • MiR 21. March 2008: Ok, actually the examples from the packages are missing, otherwise its working fine on my WinXP machine. Thx for the work, please post the drum and seq. sample.... jdc 21-mar-2008: The link was wrong, it's updated now.
  • D. McC 2008 Mar 29: Is there anything similar for unix?! jdc 31-mar-2008 On linux writing to /dev/midi should be possible. Check [L1 ] section 9.3 for an example.