zentara has asked for the wisdom of the Perl Monks concerning the following question:

Hi, the recent midi snippets have got me going on getting control over my midi. The following script runs thru each instrument patch, and prints out all the different tones of each patch. So there are (0..127) patches, and each patch has (0..127) variations. So to tune my ear, I want to just run thru all the possibilities. The following script works, but all the "patch number" text_events come out all at the beginning of play. How do I make each text_event print as the patch actually changes? Thanks.
#!/usr/bin/perl #usage: script | timidity - use MIDI::Simple; new_score; $a=1; #number of loops set_tempo 10**7*6/360; while($a--){ noop c1; for(0..127){patch_change 1,$_;text_event $_; for $x(0..127){n $x} } } write_score *STDOUT{IO};

Replies are listed 'Best First'.
Re: MIDI::Simple Timing text_events
by Mr. Muskrat (Canon) on Mar 21, 2003 at 21:53 UTC
    MIDI::Simple doesn't seem to support changing the time at which a text event occurs. It simply pushes the text event onto the stack and then they are written out at the beginning of the score no matter what. Perhaps you should ask Sean Burke (the author) about it.
Re: MIDI::Simple Timing text_events
by Coruscate (Sexton) on Mar 22, 2003 at 09:15 UTC

    Don't use text_event(). Use lyric(). And btw, the 10**7*6 I used in my script that you copied over is just a weird way of representing the number 60 million (aka 60_000_000). The purpose of the number 60_000_000 is that there are that many milliseconds in a minute. set_tempo() sets the number of milliseconds that each quarter note will play for. So 60_000_000/360 will fit 360 quarter notes in one minute.

    In your example, rather than use the auto-decrement operator, using for (1..$a) {} might be neater. The reason I used the auto-decrementer was to make it play for approxiamtely 66 seconds, no matter what tempo was selected. (As an aside, you may want to rename that $a vriable. $a and $b should be avoided as they are used in sorting. Besides, it's better to have names that make sense to what you are doing). Have fun :). I love midi so far heheh


    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.