|
Post by honkytonk on Jul 14, 2022 10:33:06 GMT
Hello everyone. My problem: I would like to play a midi file in a loop; The patern is 5 seconds long This works:
playmidi "forfor.mid", howLong if howLong = midipos( ) then stopmidi end if
This doesn't work and gives me an error: "midi file is already playing"
for x=1 to 3 gosub [tor] ' gosub [pause] next x wait [tor] playmidi "forfor.mid", howLong if howLong = midipos( ) then stopmidi end if return
How to do ? Thank you for.
|
|
|
Post by Rod on Jul 14, 2022 13:25:59 GMT
Only play the midi again if it is ended. So use a flag as well. If the flag is not set, in [tor] set it and play the midi. Then if the flag is set only play the midi if midipos() is at how long.
|
|
|
Post by honkytonk on Jul 14, 2022 16:13:06 GMT
Yes, but with: if howLong = midipos( ) then stopmidi end if Normally the file is finished and the sound stopped, right?
|
|
|
Post by Rod on Jul 14, 2022 17:52:05 GMT
howlong variable is filled with the length or end point of the midi when you issue the command playmidi. The midi plays till this position then sits and waits to be closed with stopmidi. It does not close itself. So when you ask for the midipos() and it is at howlong then you must stop midi and if you wish playmidi again. On my machine there is a delay before the midi starts. This is the voices getting loaded I think. So don’t know how well it will loop.
With Liberty you have more control using MMI to loop mp3 or .wav files
|
|
|
Post by honkytonk on Jul 14, 2022 22:11:23 GMT
The "howlong" is 65, but even doing: if midipos( )>= 50 then stopmidi end if it gives me the error. I tried tinkering with Janet's "midi player" to make it loop, but horribly complicated, but I'll try again;
Edit: Even putting a pause longer than the patern before the next There is always the error
|
|
|
Post by Rod on Jul 15, 2022 8:03:11 GMT
I can’t get to my PC I have covid and am isolating from my family. So this is pseudo code
Timer 500,[midi] Wait
[midi] If howlong=0 then playmidi "forfor.mid", howlong Else If midipos()=howlong then Stopmidi Playmidi “forfor.mid”,howlong End if End if Wait
In theory this will play forever but I think you will find there is a delay between loops as the midi resource is reloaded. This is something that Windows has introduced in recent years, it used to be seamless.
|
|
|
Post by honkytonk on Jul 15, 2022 9:02:58 GMT
I reduced janet's "midi player" to understand it. And I got to run it on a loop With a pause "midiLength*100"
Nomainwin WindowWidth = 320:WindowHeight = 220 UpperLeftX = 200: UpperLeftY = 200 Button #w.b, "Loop", [boucle], UL, 35, 50, 60, 30 textbox #w.t, 120, 50, 60, 30 Button #w.b1, "LOAD", [loadMusic], UL, 35, 130, 60, 30 Button #w.b2, "PLAY", [playMusic], UL, 127,130, 60, 30 Button #w.b3, "STOP",[stopMusic], UL, 216, 130, 60, 30 open "Just BASIC Midi Player" for Window as #w #w, "Trapclose [endProgram]" #w.t, "!font courrier 14 bold": #w.t, "3" Wait [boucle] #w.t, "!contents? bou$": bou=val(bou$): #w.t, str$(bou) bouc=1: #w.b, "!disable": #w.b2, "!disable" goto [playMusic] wait [loadMusic] FileDialog "Open Midi File", "*.mid", fileName$ If fileName$ = "" Then Wait Wait [playMusic] if bouc=0 then #w.b, "!disable": goto [play] if bouc=1 then for x=1 to bou gosub [play] gosub [pause] if x=3 then flag=0: wait StopMidi: flag=0 next x end if wait [play] flag=1 Playmidi fileName$, midiLength ' Playmidi fileName$, howlong if bouc=1 then return Wait [stopMusic] StopMidi flag=0 Wait [pause] timer midiLength*100, [temps] wait [temps] timer 0 return [endProgram] if flag=1 then StopMidi Close #w End
|
|