13 Star 21 Fork 1

ShirDon-廖显东 / EasyMIDI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

EasyMidi

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 gitee.com/shirdonl/EasyMIDI/...

How To Use

Example 1. Read and get data from midi file.

package main

import (
	"bufio"
	"fmt"
	"os"

	"gitee.com/shirdonl/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"

	"gitee.com/shirdonl/EasyMIDI/smf"
	"gitee.com/shirdonl/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

  • Shirdon - main developer - Shirdon

License

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

MIT License Copyright (c) 2018 Shirdon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

音频文件处理库 展开 收起
Go 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/shirdonl/EasyMIDI.git
git@gitee.com:shirdonl/EasyMIDI.git
shirdonl
EasyMIDI
EasyMIDI
master

搜索帮助