Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sfMidi 1.1 - Play MIDI in SFML  (Read 24643 times)

0 Members and 1 Guest are viewing this topic.

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi 1.1 - Play MIDI in SFML
« on: February 24, 2012, 07:18:33 pm »
What is sfMidi?
sfMidi is a static library for playing MIDI files with SoundFont 2 in SFML.
sfMidi uses FluidSynth (http://sourceforge.net/apps/trac/fluidsynth/) to load SoundFont 2 and MIDI files.

GitHub repository:
https://github.com/eXpl0it3r/sfMidi

Hand over to new maintainer:
After a long period of inactivity, I have decided to hand over this project to eXpl0it3r.
Please checkout the GitHub repository for the latest updates on this project.

(click to show/hide)
« Last Edit: September 30, 2018, 12:47:33 pm by zorexx »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #1 on: February 24, 2012, 08:24:36 pm »
Have you tried to render the MIDI music as audio samples instead of playing it directly? This way you could use it with the audio API (sf::Music, sf::Sound), and you wouldn't lose any feature.

http://fluidsynth.sourceforge.net/api/index.html#UsingSynth
Laurent Gomila - SFML developer

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi - Play MIDI in SFML
« Reply #2 on: February 24, 2012, 08:33:17 pm »
That is what sfMidi does, audio is played with an sf::SoundStream subclass, sf::Midi.

Edit:
Or did you mean rendering the whole midi file into memory first, then playing it from there? I thought of that before, but then I got the impression that, that would be very memory intensive. But I just did the calculation and it doesn't seem that bad actually, so maybe I'll add a PreloadMidi function or something tomorrow.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #3 on: February 24, 2012, 09:21:28 pm »
Ok sorry, I should have looked at your code first, or at least read more carefully your description of the limitation :oops:

It's interesting, that makes it a good candidate for a future plugin system. I would even have integrated it directly if the license of FluidSynth was not LGPL (which implies an extra DLL on Windows).
Laurent Gomila - SFML developer

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
sfMidi - Play MIDI in SFML
« Reply #4 on: February 25, 2012, 12:27:34 am »
I was wondering when someone would try to set this up.  Thanks! :)

By the way.. Where are you getting your Sound Fonts from?  Just wondering since I've never had to use sound fonts before in this way.  The only time I've worked with Midi files is in Java and I've never had to use sound fonts for it.  :?

An idea would be to have a default sound font in your project that doesn't change things too much.  This way someone won't have to download sound fonts if they don't want to or are easily confused like me. :)
I have many ideas but need the help of others to find way to make use of them.

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi - Play MIDI in SFML
« Reply #5 on: February 25, 2012, 02:25:11 am »
@Laurent: No problem. About integrating it into SFML, yes, the GPL family is quite a pain, but the only good alternative to this I can find is TiMIDIty++, which is GPL, there's also libjdkmidi but I didn't really look into it because it seems dead, and it's GPL again.

Actually, if the project does not use the MIDI functions, you won't have to include the dll file along with it, right?

@StormWingDelta: I got the sound font from a link in FluidSynth's website, @Stormhttp://sourceforge.net/apps/trac/fluidsynth/wiki/SoundFont
I do think you should include the SoundFont in your project, instead of expecting the user to have one, since they probably don't.

Also, before deciding to use MIDI in your project, do consider using mp3/ogg, or module files (tracker music, check out my other project, sfMod:http://www.sfml-dev.org/forum/viewtopic.php?t=6178) instead, SoundFonts are huge, putting the size on disk aside, take a look at the memory it takes up when you load it, and they are slow to load as well, so I honestly don't really recommend using MIDI in your projects unless you have to.

Edit:
Added the preloading feature and released as version 1.0.1.
Takes quite some time to preload, but you get to unload the sound font file when you're done preloading. Playing, stopping, seeking, and looping will work as if it's a normal sf::Music with preloaded data. Preloaded data is about 10MB per minute.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #6 on: February 25, 2012, 09:36:14 am »
Quote
Actually, if the project does not use the MIDI functions, you won't have to include the dll file along with it, right?

If it's compiled inside sfml-audio you will have to provide the DLL. That's why it has to be a plugin, so that people that don't need MIDI can just ignore it.
Laurent Gomila - SFML developer

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi - Play MIDI in SFML
« Reply #7 on: February 25, 2012, 09:50:24 am »
Hmm, let's say if I'm using sfml-audio to play music, but the file handling and data feeding is done through my own program via SoundStream, in other words, I'm not using the audio file loading capability of sfml, which I presume uses libsndfile.
In this case, I do not need to include the dll of libsndfile in my project, or is this a different case?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #8 on: February 25, 2012, 09:56:22 am »
Quote
In this case, I do not need to include the dll of libsndfile in my project

You do, because sfml-audio is built with a dependency to libsndfile.dll. It would be optional if it was a dynamically loaded plugin.
Laurent Gomila - SFML developer

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi - Play MIDI in SFML
« Reply #9 on: February 25, 2012, 10:11:34 am »
Really? I did not include libsndfile.dll in both sfMod and sfMidi example project, and they both work just fine. Or am I misunderstanding something?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #10 on: February 25, 2012, 02:20:47 pm »
Can you upload one of these examples?
Laurent Gomila - SFML developer

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi - Play MIDI in SFML
« Reply #11 on: February 25, 2012, 02:52:41 pm »
It is already included in the full version:
http://www.zorexxlkl.com/files/downloads/sfMidi-1.0.1-full.zip

sfMidiTest folder

for the sfMod one:
http://www.zorexxlkl.com/files/downloads/sfMod-1.0.2-full.zip

sfModTest folder

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #12 on: February 25, 2012, 03:01:07 pm »
With your examples I get "missing DLL" errors for openal32.dll and libsndfile-1.dll, as expected.

If you don't, it means that you've put these DLLs in a directory which is in your PATH environment variable.
Laurent Gomila - SFML developer

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
sfMidi - Play MIDI in SFML
« Reply #13 on: February 25, 2012, 03:20:09 pm »
Really? That's odd, because I even tried with libfluidsynth, which I just compiled, and I'm very sure it's not in any directory under my PATH environment variable.

I did this test:
In the sfMidi project, run as usual, works, delete libfluidsynth, does not work (missing dll), edit the file to exclude all the sfMidi functions, (actually, i put those in an if (false) scope), compile, now it works, no missing dll error.

Just wondering, did you recompile the project or run it directly?


Edit:
I just tested it on my sister's laptop, she does not do any sort of programming, and the only missing dlls are msvcp100.dll and msvcr100.dll (runs fine without libfluidsynth.dll as long as I don't call any function from sfMidi)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sfMidi - Play MIDI in SFML
« Reply #14 on: February 25, 2012, 04:41:51 pm »
You can check which DLLs an executable or DLL depends on with Dependency Walker.

And I find a little strange that your example can run without openal32.dll too -- this one is definitely needed ;)

Quote
Just wondering, did you recompile the project or run it directly?

I ran it directly.

Quote
I did this test:
In the sfMidi project, run as usual, works, delete libfluidsynth, does not work (missing dll), edit the file to exclude all the sfMidi functions, (actually, i put those in an if (false) scope), compile, now it works, no missing dll error.

It depends how you build sfMidi and the application that uses it. I haven't looked, so I cannot say anything about it.

But anyway, sfml-audio calls functions of libsndfile and openal, so even if what you say was true it wouldn't change anything.

EDIT: do you link SFML statically or dynamically?
Laurent Gomila - SFML developer

 

anything