Garry's Mod

Garry's Mod

64 ratings
MIDI Player
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Tool
File Size
Posted
Updated
6.490 MB
29 May, 2017 @ 5:34pm
22 May, 2021 @ 10:49pm
4 Change Notes ( view )

Subscribe to download
MIDI Player

Description
Play MIDI files in Garry's Mod! You can load MIDI files from your garrysmod folder, or from an internet URL.

How to use:

Step 1: Acquire MIDI files
Put some MIDI files in your 'GarrysMod/garrysmod' folder, or find some somewhere online.
The Video Game Music Archive[vgmusic.com] has plenty of MIDIs with varying quality.

Step 2: Get in-game
You should know how to do this. Start a single-player game, or join a server that has this addon installed.

Step 3: Open the spawn menu
You should also know how to do this. Just press and hold 'Q'.

Step 4: Utilities tab
It's the one on the far right.

Step 5: Select MIDI Player - Control
You should see it in your tool list.

Step 6: Use interface to load a MIDI
Either double-click a MIDI file you placed into your garrysmod folder earlier, or paste in a URL and click 'Load'

Step 7: Listen to music

Known Issues:
This MIDI player is far from perfect. Several issues with sound playback in the Source engine prevent any improvements. The only likely path to improving this MIDI player is for Garry's Mod to ditch its outdated Chrome 18 based embedded browser (Awesomium) with one based on modern versions of Chrome (Chromium Embedded Framework). Then, an HTML5 implementation of a more accurate MIDI player can be used. Until then, here's whats wrong, in the order it bothers me the most:

  • Notes that require a sound to be pitch-shifted by a factor higher than 2.55 will be ignored. While an upper limit makes sense, Source made it way too low.
  • If too many notes are played at once using the same sound file, some of them will be ignored. This is due to limitations in Source.
  • The pitch of a note will not always be accurate. This is due to Source forcing what should be a floating point number into an 8-bit integer.
  • Volume of notes may be wrong. The cause of this is unknown, but is probably the fault of Source. An HTML5 version of the MIDI player using the same methods produces correct output.
  • The implementation of the SoundFont 2 spec is not complete. This is due to limitations in Source, and me being lazy.

ADVANCED USERS ONLY! Using custom soundfonts:

This addon supports custom soundfonts, however, the Source Engine cannot play sounds directly from the soundfont. The sounds need to be extracted, have their sampling rate changed to something that the Source Engine will play, saved as *.wav files, and placed in the appropriate folder. I've included a Lua function that can do most of this for you, but you still have to do a little legwork yourself.

First, you must place the soundfont into your garrysmod folder. Then, run some Lua code:

midi.LoadSF("mysoundfont.sf2")
midi.sf:DumpSamples()

This will dump out the sounds into your garrysmod data folder, with the naming convention "garrysmod/data/mysoundfont.sf2/*.wav.txt". You must remove the .txt extension from each sound file, then move the whole "mysoundfont.sf2" folder into "garrysmod/sound/soundfont". The final path of the sounds should be "garrysmod/sound/soundfont/mysoundfont.sf2/*.wav".

Then you are all set. Any time you want to use that soundfont, you must run this bit of Lua:

midi.LoadSF("mysoundfont.sf2")

Any midi you play after this will use the new soundfont, until the client changes maps, disconnects, or exits.

Though this is possible to do, I do not recommend it. Most soundfonts will probably sound horrible due to the Source Engine limitations I mentioned.
Popular Discussions View All (1)
0
18 May, 2021 @ 8:24am
Unable to install?
Spooner4Life
37 Comments
Jcw87  [author] 24 Mar, 2023 @ 1:36pm 
CLuaRainBob 23 Mar, 2023 @ 1:31am 
github?
Jcw87  [author] 21 May, 2021 @ 9:41pm 
Technically, it does, but if the server didn't install it, you have to jump through a few hoops.


1. The server needs to enable sv_allowcslua.
2. Even with client-side Lua allowed, autorun scripts are not executed. You will have to run the loader yourself with lua_openscript_cl.
3. Due to bugs that existed in gmod's built-in VGUI controls at the time, I had to bundle my own versions of those controls with the bugs fixed. These files are normally executed by gmod automatically, except of course when you are trying to run client-side code that the server did not send you. You need to run these files too.
4. The spawnmenu initializes itself before you have a chance to enter anything into your console, so you will have to issue a spawnmenu_reload command.
Spooner4Life 17 May, 2021 @ 9:23am 
So the MIDI player doesn't work in multiplayer servers apparently
Spooner4Life 16 May, 2021 @ 10:35am 
i found out the problem don't worry about it
Spooner4Life 16 May, 2021 @ 10:26am 
[MIDI Player] lua/midiplayer/player.lua:84: attempt to index global 'stream' (a nil value)
1. LoadMidiFromFile - lua/midiplayer/player.lua:84
2. OnDoubleClick - lua/midiplayer/ui.lua:72
3. DoDoubleClick - lua/vgui/dfilebrowser_midi.lua:183
4. OnClickLine - lua/vgui/dlistview.lua:410
5. unknown - lua/vgui/dlistview_line.lua:81
A little help please?
Strix Aki 27 Apr, 2020 @ 11:50am 
nice >:]
Souper 5 Apr, 2020 @ 8:34pm 
Feel free to make the HTML5 implementation, since Chromium's soon replacing Awesomium (if it hasn't already done so).
VMan_2002 13 Aug, 2019 @ 10:53pm 
GMod can use Chromium. Right click in library -> Properties -> Click Betas tab -> Choose "chromium -" from the drop-down box. Please make a version using chromium
fggfhfgdhjgdsf 24 Jun, 2019 @ 8:32am 
who's been drawing dicks