From 822668e3805fcc24340e2d8dd9e4f87e66beca8c Mon Sep 17 00:00:00 2001 From: Mark Kremer Date: Thu, 1 Aug 2024 20:44:45 +0200 Subject: [PATCH] Let the user close the sound font io.Reader themselves --- examples/midi/main.go | 4 ++++ midi/decode.go | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/midi/main.go b/examples/midi/main.go index b7bb837..ac9fd55 100644 --- a/examples/midi/main.go +++ b/examples/midi/main.go @@ -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) @@ -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) diff --git a/midi/decode.go b/midi/decode.go index 3acafe7..338150f 100644 --- a/midi/decode.go +++ b/midi/decode.go @@ -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) { sf, err := meltysynth.NewSoundFont(r) if err != nil { return nil, err } - err = r.Close() - if err != nil { - return nil, err - } return &SoundFont{sf}, nil }