Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/algoGuy/EasyMIDI
EasyMidi is a simple and reliable library for working with standard midi file (SMF)
https://github.com/algoGuy/EasyMIDI
Last synced: 3 months ago
JSON representation
EasyMidi is a simple and reliable library for working with standard midi file (SMF)
- Host: GitHub
- URL: https://github.com/algoGuy/EasyMIDI
- Owner: algoGuy
- License: mit
- Created: 2018-02-19T20:18:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-22T05:16:54.000Z (about 6 years ago)
- Last Synced: 2024-01-15T00:52:28.152Z (5 months ago)
- Language: Go
- Size: 54.7 KB
- Stars: 40
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go - EasyMIDI - | (Audio and Music)
- awesome-go-with-framework - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-reader - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go. - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-Char - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music / Contents)
- awesome-go-cn - EasyMIDI
- awesome-go-handwritten - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go2 - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF). (Audio and Music)
- awesome-go - EasyMIDI - EasyMidi is a simple and reliable library for working with standard midi file (SMF) - ★ 15 (Audio and Music)
- awesome-go-cn - EasyMIDI
README
# EasyMidi
[![codecov](https://codecov.io/gh/algoGuy/EasyMIDI/branch/master/graph/badge.svg)](https://codecov.io/gh/algoGuy/EasyMIDI) [![Build Status](https://semaphoreci.com/api/v1/algoguy/easymidi/branches/master/badge.svg)](https://semaphoreci.com/algoguy/easymidi) [![Go Report Card](https://goreportcard.com/badge/github.com/algoGuy/EasyMIDI)](https://goreportcard.com/report/github.com/algoGuy/EasyMIDI)
[![GoDoc](https://godoc.org/github.com/algoGuy/EasyMIDI?status.svg)](https://godoc.org/github.com/algoGuy/EasyMIDI)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#audio-and-music)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.
```go
package mainimport (
"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.
```go
package mainimport (
"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](https://golang.org/) - The Go Programming Language
## Authors
* **algoGuy** - *main developer* - [algoGuy](https://github.com/algoGuy)
* **iqhater** - *main contributer* - [iqhater](https://github.com/iqhater)## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details