electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Writing MIDI files?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
robhamilton



Joined: Jan 12, 2008
Posts: 8
Location: Stanford, CA

PostPosted: 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?
Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Thu May 26, 2016 1:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24079
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Thu May 26, 2016 1:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
robhamilton



Joined: Jan 12, 2008
Posts: 8
Location: Stanford, CA

PostPosted: Thu May 26, 2016 3:39 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yes, not human readable, standard MIDI format. This code feels old and abandoned; like the Audicle.
Back to top
View user's profile Send private message Visit poster's website
MusicMan11712



Joined: Aug 08, 2009
Posts: 1082
Location: Out scouting . . .

PostPosted: Mon May 30, 2016 4:51 pm    Post subject: Reply with quote  Mark this post and the followings unread

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." Wink

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
View user's profile Send private message
MusicMan11712



Joined: Aug 08, 2009
Posts: 1082
Location: Out scouting . . .

PostPosted: Thu Aug 04, 2016 7:39 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use