Guidance
指路人
g.yi.org
Software / Reginald / Examples / rxmidi examples / newmidi.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* Create a new MIDI file */

OPTIONS "C_CALL LABELCHECK NOSOURCE"

/* Add the REXX GUI and RxMidi functions */
LIBRARY rexxgui, rxmidi

/* Trap errors in RxMidi functions. So, we don't have to check the return values
 * from MIDI REXX functions that set the ERROR condition, such as MIDISetEvent() */
midierr = "ERROR"
midiheading = 1

/* Print an introduction */
IF guisay('This script creates a new MIDI file. Proceed?', 'YES|INFO', 'New MIDI') \= 'YES' THEN SIGNAL out

/* Check if we have a MIDI file name. We get the filename from
 * the command line (ie, the user typed it after disasm.rex), or
 * if not supplied, we bring up the file dialog.
 */
IF ARG() < 1 THEN DO
	ERROR = guifile('FromFilename', 'OVERWRITE|SAVE', 'Enter a name for the new MIDI file', 'MIDI files (*.mid, *.rmi) | *.mid;*.rmi | All files (*.*) | *.*')
	IF ERROR \= "" THEN RETURN
END
ELSE fromfilename = ARG(1)

/* Make sure that name ends in .MID */
IF TRANSLATE(RIGHT(fromfilename, 4)) \== ".MID" THEN fromfilename = fromfilename || '.mid'

DO

	/* Create a new MIDI file in RAM with 96 PPQN resolution */
	MIDIOpenFile()

	/* All events will be on first MIDI channel */
	midievent.!channel = 1

	/* First event will be at the first downbeat (ie, 1:1:0) */
	midievent.!measure = 1
	midievent.!beat = 1
	midievent.!clock = 0

	/* Add a Seq # event at the end of the first track */
	midievent.!type = "Seq "
	midievent.!data1 = 10		/* Seq # = 10 */
	MIDISetEvent('INS|TIME|DATA', 1)	/* For the first event, we select the track # we want */

	/* Add a Track Name event at the end of the first track */
	midievent.!type = "Trac"
	midievent.!data1 = "Dummy"
	MIDISetEvent('INS|TIME|DATA')		/* All other events, we use the currently selected track */

	/* Add an Instrument event at the end of the first track */
	midievent.!type = "Inst"
	midievent.!data1 = "Piano"
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Text event at the end of the first track */
	midievent.!type = "Text"
	midievent.!data1 = "Here's text"
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Time Sig event at the end of the first track */
	midievent.!type = "Time"
	midievent.!data1 = 2	/* 2/2 Time */
	midievent.!data2 = 2
	midievent.!data3 = 24	/* MIDI-clocks\click */
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Key Sig event at the end of the first track */
	midievent.!type = "Key "
	midievent.!data3 = "G Major"
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Tempo event */
	midievent.!type = "Temp"
	midievent.!data1 = 600000  /* micros\quarter */
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Port # event */
	midievent.!type = "Port"
	midievent.!data1 = 0
	MIDISetEvent('INS|TIME|DATA')

	/* Second Beat of first measure */
	midievent.!beat = 2

	/* Add an On Note event (on first MIDI channel) */
	midievent.!type = "On N"
	midievent.!data1 = MIDINoteNum("E3")	/* note number */
	midievent.!data2 = 127					/* velocity */
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* Add a Program event */
	midievent.!type = "Prog"
	midievent.!data1 = 1	/* program number (referenced from 0) */
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* Add a Sysex event */
	midievent.!type = "Syse"
	midievent.!data1 = "F0 01 F7"x  /* Or we could do MIDIEvent.!Data1 = X2C("F001F7") */
	MIDISetEvent('INS|TIME|DATA')

	/* Add an On Note event */
	midievent.!type = "On N"
	midievent.!data1 = MIDINoteNum("B3")
	midievent.!data2 = 127
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* First Beat of second measure */
	midievent.!measure = 2
	midievent.!beat = 1

	/* Add a MIDI Stop event */
	midievent.!type = "Stop"
	MIDISetEvent('INS|TIME|DATA')

	/* Add an On Note event */
	midievent.!type = "On N"
	midievent.!data1 = MIDINoteNum("G#3")
	midievent.!data2 = 127
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* Second Beat of second measure */
	midievent.!beat = 2

	/* Add an (Off) Note event */
	midievent.!type = "(Off"
	midievent.!data1 = MIDINoteNum("e3")
	midievent.!data2 = ''
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* Add a Tempo event */
	midievent.!type = "Temp"
	midievent.!data1 = 500000
	MIDISetEvent('INS|TIME|DATA')

	/* Add an (Off) Note event */
	midievent.!type = "(Off"
	midievent.!data1 = MIDINoteNum("g#3")
	/* MIDIEvent.!Data2 = '' */
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* First Beat of third measure */
	midievent.!measure = 3
	midievent.!beat = 1

	/* Add a First Packet event */
	midievent.!type = "Firs"
	midievent.!data1 = "F0 02"x
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Packet event */
	midievent.!type = "Pack"
	midievent.!data1 = "03"x
	MIDISetEvent('INS|TIME|DATA')

	/* Add a Last Packet event */
	midievent.!type = "Last"
	midievent.!data1 = "04 F7"x
	MIDISetEvent('INS|TIME|DATA')

	/* First Beat of fourth measure */
	midievent.!measure = 4

	/* Add a Specific event */
	midievent.!type = "Spec"
	midievent.!data1 = "00 01 02 03"x
	MIDISetEvent('INS|TIME|DATA')

	/* Add an (Off) Note event */
	midievent.!type = "(Off"
	midievent.!data1 = MIDINoteNum("b3")
	/* MIDIEvent.!Data2 = '' */
	MIDISetEvent('INS|TIME|DATA|CHAN')

	/* Set time to 4:1:30 */
	midievent.!clock = 30

	/* Add an End of Track event */
	midievent.!type = "End "
	MIDISetEvent('INS|TIME')

	/* Save to a MIDI file */
	MIDISaveFile(fromfilename)

	CATCH ERROR
		CONDITION('M')
END

RETURN
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-27  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:49:22