Skip to content

garrysmodlua/GLua-midi-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIDI Parser for Garry's Mod Lua

MIT License Travis Build Status

It is not perfect! Use it for experimental purposes.
This is a GLua fork of Lua_midiParser.

Installation

Download

You must download the source code first, there are 4 ways to do it, use any way you like:

  • Download the latest release from here.
  • Download ZIP of this repository here.
  • Clone this repository using git: git clone https://github.com/garrysmodlua/GLua-midi-parser.git midi-parser.
  • Save the midi-parser.lua file (Press Ctrl+S; Or, Cmd+S on Mac).

GMod Setup

  1. Navigate to your ./Steam/steamapps/common/GarrysMod/garrysmod folder.
  2. Depending on which download method you have used, make sure you have the following directory structure (create any necessary folder yourself if it doesn't exist):

Expected directory structure

  1. You are done. Have fun!

Usage / Code Example

  1. Must require our midi-parser module:

    require( "midi-parser" )
  2. Call either of these 2 functions:

    • [table] = midi.Parse(string midiData) - To parse MIDI data as string.
    • [table] = midi.ParseFile(string fileName[, string path="DATA"]) - To parse a given .mid file.
-- Notes/Information:
-- ParseFile function: A fileName argument, if you are dealing with multiple directories, remember to use forward-slash (/) character as directory separator; do NOT use backslash (\) character.
-- ParseFile function: A path argument is optional, it defaults to "DATA" when omitted; by default it will search relative to "GarrysMod/garrysmod/data" folder.
-- Both of the Parse functions will throw an error if something goes wrong (e.g. if a given file does not exist, or could not be read, etc).
-- Moreover, if MIDI file/data is succesfully parsed, a function will return a table as a result.

local firstMidi = midi.ParseFile( "midis/first.mid" ) -- Will attempt to parse "GarrysMod/garrysmod/data/midis/first.mid" file

local testingMidi = midi.ParseFile( "test.mid", "LUA" ) -- Will attempt to parse "GarrysMod/garrysmod/lua/test.mid" file

PrintTable( testingMidi ) -- Prints the contents of testingMidi table

Return Sample

{
	format = 1,
	timebase = 96,
	tracks = {
		{
			messages = {
				{
					time = 0,
					type = "meta",
					meta = "Time Signature",
					signature = { 4, 2, 24, 8 }
				},
				{
					time = 0,
					type = "meta",
					meta = "End of Track"
				}
			}
		},
		{
			messages = {
				{
					time = 0,
					type = "meta",
					meta = "Set Tempo",
					tempo = 468375
				},
				{
					time = 0,
					type = "meta",
					meta = "End of Track"
				}
			}
		},
		{
			name = "TrackName",
			messages = {
				{
					time = 0,
					type = "meta",
					meta = "Track Name",
					text = "TrackName"
				},
				{
					time = 0,
					type = "on",
					channel = 0,
					number = 48,
					velocity = 100
				},
				{
					time = 96,
					type = "off",
					channel = 0,
					number = 48,
					velocity = 64
				},
				{
					time = 0,
					type = "meta",
					meta = "End of Track"
				}
			}
		}
	}
}

Documentation

Sorry, there is no wiki nor docs...

Contribution

Visit the Contributor Guidelines for more details. All contributors are expected to follow our Code of Conduct.

Support

If you think you have found a bug or have a feature/enhancement request for GLua MIDI parser, use our issue tracker.

Before opening a new issue, please be kind and search to see if your problem has already been reported. Try to be as detailed as possible in your issue reports.
When creating an issue, clearly explain

  • What you were trying to do?
  • What you expected to happen?
  • What actually happened?
  • Steps to reproduce the problem.

Also include any other information you think is relevant to reproduce the problem.

License

GLua MIDI parser repository/code is freely distributed under the MIT license. See LICENSE for more details.

Credits

FMS-Cat for the original Lua code.
CaptainPRICE for making it compatible with Garry's Mod (GLua).

Related Projects

GMod-Expression2-midi-parser: MIDI Parser (Wire Expression 2 extension).