Skip to content

Commit

Permalink
Let the user close the sound font io.Reader themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKremer committed Aug 1, 2024
1 parent c253ead commit 48a5d9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 4 additions & 0 deletions examples/midi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
if err != nil {
log.Fatal(err)
}
defer soundFontFile.Close()

soundFont, err := midi.NewSoundFont(soundFontFile)
if err != nil {
log.Fatal(err)
Expand All @@ -34,6 +36,8 @@ func main() {
if err != nil {
log.Fatal(err)
}
defer midiFile.Close()

s, format, err := midi.Decode(midiFile, soundFont, sampleRate)
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 1 addition & 7 deletions midi/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ const (
)

// NewSoundFont reads a sound font containing instruments. A sound font is required in order to play MIDI files.
//
// NewSoundFont closes the supplied ReadCloser.
func NewSoundFont(r io.ReadCloser) (*SoundFont, error) {
func NewSoundFont(r io.Reader) (*SoundFont, error) {
sf, err := meltysynth.NewSoundFont(r)
if err != nil {
return nil, err
}
err = r.Close()
if err != nil {
return nil, err
}
return &SoundFont{sf}, nil
}

Expand Down

0 comments on commit 48a5d9b

Please sign in to comment.