09-03-2023, 01:52 AM
(09-03-2023, 01:37 AM)mnrvovrfc Wrote: Welcome to consequences with using MIDI and Soundfonts. The Soundfont will become part of the EXE file to ensure playback of any MIDI file that could possibly use that Soundfont. The system cannot assume which patch will be used, so it could include a few and throw away the others. This malady happens anywhere else that a Soundfont has to be packed along with other data and the execution of music related to it.This solution is stupid and bears no relation to the actual use.
I think that if you use the API MCIsendStringA via Winmm, it's 10 times more optimal than if everything is shot into the EXE.
As I said: The sound font is 1 to 3MB in size. The midi only few bytes. And that becomes a 200MB file in the EXE? This is absolutely unacceptable. For a midi probably noted. Who programmed that?
This solution is already better. But I can't send the MIDI from a buffer to the MCI. Anyway, don't know exactly how.
Code: (Select All)
DECLARE DYNAMIC LIBRARY "WINMM"
FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
END DECLARE
DIM filedata AS STRING
SCREEN 13
filedata = "game-over.mid"
StartMID (filedata)
DO
_LIMIT 30
LOOP UNTIL INKEY$ <> ""
StopMID (filedata)
END
'==================================================================
SUB StartMID (filename AS STRING)
' Loading File in a Buffer
' ----------------------------------------
'DIM SIZE AS _UNSIGNED LONG
'DIM BUFFER AS STRING
'
'OPEN filename FOR BINARY ACCESS READ AS #1
'SIZE = LOF(1)
'BUFFER = SPACE$(SIZE)
'GET #1, , BUFFER
'CLOSE #1
' ----------------------------------------
ReturnString$ = SPACE$(255): ErrorString$ = SPACE$(255)
a% = mciSendStringA%("open " + filename + " type sequencer ", ReturnString$, LEN(ReturnString$), 0)
IF a% THEN
x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
PRINT ErrorString$
END
END IF
b% = mciSendStringA%("play " + filename, "", 0, 0)
END SUB
SUB StopMID (filename$)
x% = mciSendStringA%("stop " + filename$, "", 0, 0)
x% = mciSendStringA%("close " + filename$, "", 0, 0)
END SUB