IonicWind Software

IWBasic => General Questions => Topic started by: yujinwunz on January 26, 2009, 03:40:29 PM

Title: looping midi s
Post by: yujinwunz on January 26, 2009, 03:40:29 PM
hi everyone

i am trying to get midi to loop. i cant seem to find it in the user guide or any older support forums. can anyone help me?

any response is greatly appriciated.
Title: Re: looping midi s
Post by: LarryMc on January 26, 2009, 03:45:07 PM
from the help file midi section:

Quote@SNDLOOP - The sound plays repeatedly. You must also specify @SNDASYNC.
???

Can't see how you missed it.

Larry
Title: Re: looping midi s
Post by: yujinwunz on January 26, 2009, 03:52:47 PM
Quote from: Larry McCaughn on January 26, 2009, 03:45:07 PM
from the help file midi section:

Quote@SNDLOOP - The sound plays repeatedly. You must also specify @SNDASYNC.
???

Can't see how you missed it.

Larry

i saw that on PLAYWAVE but not on PLAYMIDI. how can i use it on PLAYMIDI?
Title: Re: looping midi s
Post by: LarryMc on January 26, 2009, 04:08:38 PM
My mistake; I had a senior moment.

Larry
Title: Re: looping midi s
Post by: LarryMc on January 26, 2009, 04:21:48 PM
Old IB Std code from Tony about looping midis"

Maybe it will help you
you'll have to insert carriage returns to be able to read it easily

Larry

See Tony's cleanedup code below
Title: Re: looping midi s
Post by: Tony on January 26, 2009, 05:16:48 PM
Here's a cleaned up version of the code. You will still need to make minor changes for use with EBasic.

REM an example of using Windows MCI to play and loop through a MIDI file.
REM Only one delcare needed.
DECLARE "winmm",mciSendStringA(lpszCommand:STRING,lpszReturnString:STRING,Return:INT,hwndCallback:int),int
DEF filename:STRING
DEF filter:STRING
DEF command,status:STRING
DEF w1:window

WINDOW w1,0,0,350,350,@MINBOX|@MAXBOX,0,"Midi Player",mainwindow
menu w1,"T,&File,0,0","I,&Play MIDI,0,1","I,&Quit,0,2" 
filter = "MIDI files (*.mid)|*.mid||" 
run = 1
waituntil run=0
command = "close mymidi"
mciSendStringA(command,"",0,0)
closewindow w1
end

SUB mainwindow
select @class
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
run = 0
CASE @IDMENUPICK
SELECT @MENUNUM
CASE 1
filename = FILEREQUEST("Open MIDI file",w1,1,filter)
if(len(filename))
command = "close mymidi"
mciSendStringA(command,"",0,0)
command = "open " + CHR$(34) + filename + CHR$(34) + " type sequencer alias mymidi"
mciSendStringA(command,"",0,0)
command = "play mymidi"
mciSendStringA(command,"",0,0)
command = "set mymidi time format SMPTE 24"
mciSendStringA(command,"",0,0)
command = "info mymidi file wait"
mciSendStringA(command,status,254,0)
move w1,10,10
print w1,status
command = "status mymidi length"
mciSendStringA(command,status,254,0)
status = left$(status,8)
move w1,10,30
print w1,"Length: ",status
starttimer w1,200
endif
CASE 2
run = 0   
ENDSELECT
CASE @IDTIMER
' See if we need to start from the
' beginning of the midi file
CheckMidi
endselect
RETURN

' Controls looping through the midi file
SUB CheckMidi
DEF RetVal:INT
DEF RetStr:STRING

RetVal = mciSendStringA("status mymidi mode", RetStr, 255, 0)

IF RetVal <> 0 THEN GOTO ExitCheckMidi

IF LEFT$(RetStr, 7) = "stopped"
StopMidi
PlayMidi
ENDIF

ExitCheckMidi:

RETURN

' Stops the midi file

SUB StopMidi

DEF RetVal:INT
DEF RetStr:STRING

RetVal = mciSendStringA("status mymidi mode", RetStr, 255, 0)

IF LEFT$(RetStr, 7) = "playing"
RetVal = mciSendStringA("stop mymidi", 0, 0, 0)
GOTO ExitStopMidi
ENDIF

RetVal = mciSendStringA("status mymidi mode", RetStr, 255, 0)

If LEFT$(RetStr, 7) = "stopped"
RetVal = mciSendStringA("close mymidi", "", 0, 0)
ENDIF

ExitStopMidi:

RETURN

' Plays the midiSUB
PlayMidi

command = "open " + CHR$(34) + filename + CHR$(34) + " type sequencer alias mymidi"

mciSendStringA(command,"",0,0)

command = "play mymidi"

mciSendStringA(command,"",0,0)

RETURN