Author |
Message |
robhamilton
Joined: Jan 12, 2008 Posts: 8 Location: Stanford, CA
|
Posted: Thu May 26, 2016 12:55 pm Post subject:
Writing MIDI files? Subject description: Does ChucK's MidiRW class actually work _or_ how can we write MIDI files from ChucK? |
|
|
Can anyone point me to a working example for writing of MIDI files?
In https://chuck-dev.stanford.edu/svn/chuck/trunk/src/midiio_rtmidi.h we can see that there was (at least in 2005) an attempt to add MidiRW and MidiMsgOut as potential routes for writing midi messages to file.
Any successful uses of this? Something like this example should work but the output isn't readable:
// ------------------------
// hacktastic midi-writer
// ------------------------
MidiRW mfile;
MidiMsg msg;
mfile.open( me.sourceDir() + "midiOut.mid" );
time currentTime;
// note on
0x90 => msg.data1;
60 => msg.data2;
127 => msg.data3;
now + 0::second => currentTime;
mfile.write(msg, currentTime);
// advance time
1000::ms => now;
// note off ( 0 => velocity)
0x80 => msg.data1;
60 => msg.data2;
0 => msg.data3;
now + 1000::ms => currentTime;
mfile.write(msg, currentTime);
mfile.close(); |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Thu May 26, 2016 1:42 pm Post subject:
|
|
|
When with 'readable' you mean 'human readable' ... MIDI files are not supposed to be human readable. But maybe you meant them to not be machine readable.
Maybe you could attach the resulting midiOut.mid file here? _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Thu May 26, 2016 1:46 pm Post subject:
|
|
|
Hmm .. I just had a look at https://chuck-dev.stanford.edu/svn/chuck/trunk/src/midiio_rtmidi.cpp - it does not look like that code is working with a standard midi file format but with something only ChucK could read or write.
Code: | t_CKBOOL MidiRW::read( MidiMsg * msg, t_CKTIME * time )
{
if( !file )
return FALSE;
// is it open? i don't know...
t_CKBOOL m, t;
// wouldn't it be cool if this worked?
m = fread( msg, sizeof(MidiMsg), 1, file );
t = fread( time, sizeof(t_CKTIME), 1, file );
return m && t;
}
t_CKBOOL MidiRW::write( MidiMsg * msg, t_CKTIME * time )
{
if( !file )
return FALSE;
t_CKBOOL m, t;
m = fwrite( msg, sizeof(MidiMsg), 1, file );
t = fwrite( time, sizeof(t_CKTIME), 1, file );
fflush( file );
return m && t;
} |
_________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
robhamilton
Joined: Jan 12, 2008 Posts: 8 Location: Stanford, CA
|
Posted: Thu May 26, 2016 3:39 pm Post subject:
|
|
|
Yes, not human readable, standard MIDI format. This code feels old and abandoned; like the Audicle. |
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Mon May 30, 2016 4:51 pm Post subject:
|
|
|
It's been quite a while since I did anything with ChucK. A few years ago I used ChucK scripts as an on-the-fly midi router--so I could direct hardware midi controllers to hardware midi sound modules by starting and stopping scripts in mini audicle.
I looked at the portion of the code for midi and saw some problems. I seem to remember discussing them with Jan and maybe others. I may have been looking for ways to send sysex commands by ChucK scripts. Totally impossible due to the incomplete/erroneous implementation of midi.
If I recall correctly the midi structure was based on 3-byte commands. I think even 1-byte commands and 2-byte commands sent 3-bytes (possibly).
Anyhow, I saw enough to know that (1) it wasn't gonna happen, (2) I didn't have the skills to rewrite ChucK source code, (3) midi was a low priority for the developers (their primary interest was audio), and (4) PC users were not a priority.
I don't know if anything changed since I last looked at ChucK.
I did not try anything with writing midi files via Chuck; I was strictly doing realtime processing of midi data with ChucK (using Win XP) as my router.
Not sure that helps, but maybe if only to confirm that the midi mplementation might not be "up to code."
Steve
ADDENDUM: http://electro-music.com/forum/post-267524.html#267524
That's just my report on what I did, not the discussion of the midi sourcecod3e issue. |
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Thu Aug 04, 2016 7:39 pm Post subject:
|
|
|
I just stumbled onto a thread here about having ChucK try to read a midi file. http://electro-music.com/forum/post-392872.html#392872 I think it relates to the same problem--basically I believe R/W *.mid files was never successfully implemented. |
|
Back to top
|
|
|
|