Giter Club home page Giter Club logo

glua-midi-parser's Introduction

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.