QB64 Phoenix Edition
Looking for a MIDI solution - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Looking for a MIDI solution (/showthread.php?tid=1962)

Pages: 1 2 3


Looking for a MIDI solution - SagaraS - 09-02-2023

I'm looking for a solution how I can play MIDI music within a file and then repeat itself over and over again.

As an example:
The Music.mid is in an archive at offset address &H400.
For example, I want to load the data into an array and send it to an API like Winmm. Is that possible? And if so how?
Or are there better alternatives for such a project?

The archive is nothing special. Is simply a raw archive.


RE: Looking for a MIDI solution - bplus - 09-02-2023

Wiki claims Midi can be played thusly: 
https://qb64phoenix.com/qb64wiki/index.php/DLL_Libraries


RE: Looking for a MIDI solution - SMcNeill - 09-02-2023

(09-02-2023, 07:35 PM)bplus Wrote: Wiki claims Midi can be played thusly: 
https://qb64phoenix.com/qb64wiki/index.php/DLL_Libraries

Even easier: Our new sound libraries support it natively.

MidiSoundFont


RE: Looking for a MIDI solution - SMcNeill - 09-02-2023

$UNSTABLE:MIDI

' Using a custom soundfont rather than the default
$MIDISOUNDFONT: "soundfont.sf2"

_SNDPLAYFILE "example.mid"


RE: Looking for a MIDI solution - DSMan195276 - 09-02-2023

(09-02-2023, 07:17 PM)SagaraS Wrote: The Music.mid is in an archive at offset address &H400.
For example, I want to load the data into an array and send it to an API like Winmm. Is that possible? And if so how?
In addition to what the others have said about QB64-PE's native MIDI support (using `$Unstable:Midi` and `$MidiSoundFont`), QB64-PE also has the ability to load music files (such as MIDI) from a string rather than a file, see the notes on using the `"MEMORY"` capability with _SNDOPEN.

Point being, you can open your archive file yourself, seek to `&H400` and read the contents of `Music.mid` into a `String`, and then pass that `String` directly to `_SNDOPEN` to be able to play it. Doing it that lets you play the sound without `Music.mid` being in a separate file. You can see an example of this at the bottom of the `_SNDOPEN` page, it reads the sound from `DATA` statements rather than from within a separate file but the concept is the same.


RE: Looking for a MIDI solution - SagaraS - 09-03-2023

Is there any alternative other than $unstable:midi and soundfonts?
Because the file is over 200MB in size when I use the commands.
That's out of all proportion.
I have a gm.sf2 that is almost 3MB and a midi file with almost 400 bytes
Then why is the EXE over 200MB?
Without $unstable:midi and soundfonts, the EXE is just 2MB in size.
What is QB64PE doing there? That's stupid.

Would like to use the tools of Windows. So no sound fonts.


RE: Looking for a MIDI solution - SMcNeill - 09-03-2023

Can you share the code and file?  Something is wrong if it's a 200mb file.


RE: Looking for a MIDI solution - SpriggsySpriggs - 09-03-2023

You can use MCISendString, I believe.


RE: Looking for a MIDI solution - SagaraS - 09-03-2023

(09-03-2023, 12:43 AM)SMcNeill Wrote: Can you share the code and file?  Something is wrong if it's a 200mb file.
Code: (Select All)
$Unstable:Midi
$MidiSoundFont:Big GrinDefault

Option _Explicit

Dim buffer As String
Dim h As Long

buffer = LoadData

h = _SndOpen(buffer, "memory")

_SndLoop h

Function LoadData$
    Dim Size As _Unsigned Long
    Dim MEM As String

    Open "game-over.mid" For Binary Access Read As #1
    Size = LOF(1)
    MEM = Space$(Size)
    Get #1, , MEM
    Close #1

    LoadData$ = MEM
End Function

And this is the result:
[Image: AITFw-yHm1QKD_ijph3uAykYyLXTzkrADWzo4IpA...w1440-h856]

The midi is exactly 415 bytes in size.

(09-03-2023, 01:07 AM)SpriggsySpriggs Wrote: You can use MCISendString, I believe.
How do I do that there exactly?
So to transfer a MIDI in the buffer to the MCI?


RE: Looking for a MIDI solution - mnrvovrfc - 09-03-2023

You did not say in your OP that you wanted the MIDI file played back by the system, ie. the "GS Wavetable Synthesizer" or through a MIDI cable into a hardware synthesizer.

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.