EasyMidi is a simple and reliable library for working with standard midi file (SMF)

EasyMidi

codecov Build Status Go Report Card GoDoc Awesome

EasyMidi is a simple and reliable library for working with standard midi file (SMF).

Installing

A step by step series of examples that tell you have to get a development env running

Get repository

go get github.com/algoGuy/EasyMIDI/...

How To Use

Example 1. Read and get data from midi file.

package main

import (
	"bufio"
	"fmt"
	"os"

	"github.com/algoGuy/EasyMIDI/smfio"
)

func main() {

	// Open test midi file
	file, _ := os.Open("./Test_-_test1.mid")
	defer file.Close()

	// Read and save midi to smf.MIDIFile struct
	midi, err := smfio.Read(bufio.NewReader(file))

	if err != nil {
		fmt.Println(err)
	}

	// Get zero track
	track := midi.GetTrack(0)

	// Print number of midi tracks
	fmt.Println(midi.GetTracksNum())

	// Get all midi events via iterator
	iter := track.GetIterator()

	for iter.MoveNext() {
		fmt.Println(iter.GetValue())
	}
}

Example 2. Create and write one midi track into new midi file.

Created midi file from scratch. In current example output midi must contains one note.

package main

import (
	"bufio"
	"log"
	"os"

	"github.com/algoGuy/EasyMIDI/smf"
	"github.com/algoGuy/EasyMIDI/smfio"
)

func main() {

	// Create division
	division, err := smf.NewDivision(960, smf.NOSMTPE)
	checkErr(err)

	// Create new midi struct
	midi, err := smf.NewSMF(smf.Format0, *division)
	checkErr(err)

	// Create track struct
	track := &smf.Track{}

	// Add track to new midi struct
	err = midi.AddTrack(track)
	checkErr(err)

	// Create some midi and meta events
	midiEventOne, err := smf.NewMIDIEvent(0, smf.NoteOnStatus, 0x00, 0x30, 0x50)
	checkErr(err)
	midiEventTwo, err := smf.NewMIDIEvent(10000, smf.NoteOnStatus, 0x00, 0x30, 0x00)
	checkErr(err)
	metaEventOne, err := smf.NewMetaEvent(0, smf.MetaEndOfTrack, []byte{})
	checkErr(err)

	// Add created events to track
	err = track.AddEvent(midiEventOne)
	checkErr(err)
	err = track.AddEvent(midiEventTwo)
	checkErr(err)
	err = track.AddEvent(metaEventOne)
	checkErr(err)

	// Save to new midi source file
	outputMidi, err := os.Create("outputMidi.mid")
	checkErr(err)
	defer outputMidi.Close()

	// Create buffering stream
	writer := bufio.NewWriter(outputMidi)
	smfio.Write(writer, midi)
	writer.Flush()
}

func checkErr(err error) {
	if err != nil {
		log.Fatalln(err)
	}
}

Built With

  • Go - The Go Programming Language

Authors

  • algoGuy - main developer - algoGuy
  • iqhater - main contributer - iqhater

License

This project is licensed under the MIT License - see the LICENSE file for details

Similar Resources

Small application to convert my music library folder structure to 'crates' in the open-source DJ software Mixxx

Small application to convert my music library folder structure to 'crates' in the open-source DJ software Mixxx

Nov 18, 2022

Simple cli utility to show bitrate/samples of flac files in a directory

flac-specs Simple cli utility to show bitrate/samples of flac files in a directory I needed a quick little utility that would look at the flac files i

Dec 14, 2021

🥦 Simple OSC command executor

brOSColi - simple OSC command executor Broscoli is a simple executor of local commands, triggered by OSC messages. It can be used to run local scripts

May 2, 2022

Go models of Note, Scale, Chord and Key

gopkg.in/music-theory.v0 Music theory models in Go There's an example command-line utility music-theory.go to demo the libraries, with a bin/ wrapper.

Dec 10, 2022

A yet to be voice call application in terminal. with the power of go and webRTC (pion).

A yet to be voice call application in terminal. with the power of go and webRTC (pion).

Dec 2, 2022

Self-hosted music streaming server 🎶 with RESTful API and Web interface

Self-hosted music streaming server 🎶 with RESTful API and Web interface

Self-hosted music streaming server 🎶 with RESTful API and Web interface. Think of it as your very own Spotify!

Dec 27, 2022

A utility for sending and listening for OSC messages.

A simple utility to send and listen for OSC messages. It can also be used to send MIDI messages.

Mar 5, 2022

Download and listen music in the terminal!

Download and listen music  in the terminal!

🛑 this cli still has a lot of bugs 🛑 A simple tool to download and listen music in the terminal. You will need: golang deno v1.16+ youtube-dl Instal

Dec 2, 2022

A tool coded by GO to decode cryptoed netease music files and qqmusic files

nqdumpgo A tool coded by GO to decode cryptoed netease music files and qqmusic files 一个使用 Go 语言编写的用于解密被网易云音乐或 QQ 音乐加密的文件的程序,Go 程序在拥有与 C++程序相近的效率的同时,大大

Dec 13, 2022
Comments
  • Cannot use GetChannel() on Event returned by iterator

    Cannot use GetChannel() on Event returned by iterator

    Hey there,

    First off, thanks for the library. It's really helpful for the project I'm working on right now. One thing though that was quite a thorn in my side is the fact that you cannot use GetChannel() on an Event object, only on a MIDIEvent. This would be fine, except that you get an Event from the Track and TrackIterator types.

    I ended up creating a fork and modifying the code a bit to allow for GetChannel() to be used, but it's definitely not the cleanest/best way to do it. I ended up needing to implement GetChannel() on SysexEvent and MetaEvent, neither of which actually have a channel, so it introduces the ability for the user to call a useless function.

    I might spend some time later trying to figure out how to resolve this Event interface issue in a more elegant way, but if you have a way to correct this problem, I just wanted to bring it up. This use case is never covered in your unit tests, because you're always calling GetChannel on MIDIEvents that you create yourself. In my opinion, it doesn't do much good to be able to call GetChannel() only on an object that you yourself had to supply a channel to create.

    Edit Seems like the same problem exists for GetMetaType, which is also a useful function to be able to call when parsing a MIDI file - lest one resort to string parsing, which is never an elegant solution.

Tracker-style microtonal MIDI sequencer

Faunatone A tracker-style microtonal MIDI sequencer. Since MIDI does not have any widely-implemented native support for microtonality, Faunatone uses

Oct 25, 2022
HIDI - flexible HID to MIDI translation layer
HIDI - flexible HID to MIDI translation layer

This application is a translation layer between HID devices like keyboards or gamepads and MIDI interface

Dec 1, 2022
MIDI tunneling through BGP, for times when you want to broadcast your music instead of your IP packets.

BGPiano MIDI tunneling through BGP, for times when you want to broadcast your music instead of your IP packets. Usage bgpiano-send and bgpiano-recv Po

Jun 9, 2022
Muclean - A simple music file renamer

Muclean A simple music file renamer Installation go install github.com/CJ-Jackso

Jan 23, 2022
Like tar but different. PitCH is an archive file format that aims for high performance and minimal bloat.

Like tar but different. PitCH is an archive file format that aims for high performance and minimal bloat.

Feb 17, 2022
? ID3 decoding and encoding library for Go

id3v2 Supported ID3 versions: 2.3, 2.4 Installation go get -u github.com/bogem/id3v2 Usage example package main import ( "fmt" "log" "github.com

Dec 31, 2022
Mini audio library

malgo Go bindings for miniaudio library. Requires cgo but does not require linking to anything on the Windows/macOS and it links only -ldl on Linux/BS

Dec 31, 2022
♪ A low-level library to play sound on multiple platforms ♪

Oto (音) A low-level library to play sound. This package offers io.WriteCloser to play PCM sound. Platforms Windows macOS Linux FreeBSD OpenBSD Android

Jan 4, 2023
Go bindings for the PortAudio audio I/O library

portaudio This package provides an interface to the PortAudio audio I/O library. See the package documentation for details. To build this package you

Jan 1, 2023
Go library for searching on YouTube Music.

ytmusic Go library for searching on YouTube Music and getting other useful information. Installing go get github.com/raitonoberu/ytmusic Usage Search

Oct 15, 2022