diff --git a/examples/midi/Buy to the Beat - V2 License.md b/examples/midi/Buy to the Beat - V2 License.md new file mode 100644 index 0000000..2d36033 --- /dev/null +++ b/examples/midi/Buy to the Beat - V2 License.md @@ -0,0 +1,6 @@ +# Buy to the Beat - V2 + +Copyright (c) 2021 Robert Oost
+Soundcloud: https://soundcloud.com/sponsrob + +This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) License. To view a copy of the license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/. diff --git a/examples/midi/Buy to the Beat - V2.mid b/examples/midi/Buy to the Beat - V2.mid new file mode 100644 index 0000000..37d195a Binary files /dev/null and b/examples/midi/Buy to the Beat - V2.mid differ diff --git a/examples/midi/Florestan-Basic-GM-GS License.md b/examples/midi/Florestan-Basic-GM-GS License.md new file mode 100644 index 0000000..a513800 --- /dev/null +++ b/examples/midi/Florestan-Basic-GM-GS License.md @@ -0,0 +1,7 @@ +# Florestan Basic GM GS + +Author: Nando Florestan + +This sound font is in the public domain. + +Source: [Internet Archive](https://archive.org/details/sf2-soundfonts-free-use) diff --git a/examples/midi/Florestan-Basic-GM-GS-by-Nando-Florestan(Public-Domain).sf2 b/examples/midi/Florestan-Basic-GM-GS-by-Nando-Florestan(Public-Domain).sf2 new file mode 100644 index 0000000..74f5e7d Binary files /dev/null and b/examples/midi/Florestan-Basic-GM-GS-by-Nando-Florestan(Public-Domain).sf2 differ diff --git a/examples/midi/main.go b/examples/midi/main.go new file mode 100644 index 0000000..b7bb837 --- /dev/null +++ b/examples/midi/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "log" + "os" + "time" + + "github.com/gopxl/beep" + "github.com/gopxl/beep/midi" + "github.com/gopxl/beep/speaker" +) + +func main() { + var sampleRate beep.SampleRate = 44100 + + err := speaker.Init(sampleRate, sampleRate.N(time.Second/30)) + if err != nil { + log.Fatal(err) + } + + // Load a soundfont. + soundFontFile, err := os.Open("Florestan-Basic-GM-GS-by-Nando-Florestan(Public-Domain).sf2") + if err != nil { + log.Fatal(err) + } + soundFont, err := midi.NewSoundFont(soundFontFile) + if err != nil { + log.Fatal(err) + } + + // Load a midi track. + midiFile, err := os.Open("Buy to the Beat - V2.mid") + if err != nil { + log.Fatal(err) + } + s, format, err := midi.Decode(midiFile, soundFont, sampleRate) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("Song duration: %v\n", format.SampleRate.D(s.Len())) + speaker.PlayAndWait(s) +}