Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Created March 3, 2015 17:26
Show Gist options
  • Save RobAWilkinson/e7059face14c4454d8be to your computer and use it in GitHub Desktop.
Save RobAWilkinson/e7059face14c4454d8be to your computer and use it in GitHub Desktop.
package drum
import (
"bytes"
"encoding/binary"
// "math"
// "encoding/hex"
"fmt"
"io/ioutil"
// "reflect"
)
// DecodeFile decodes the drum machine file found at the provided path
// and returns a pointer to a parsed pattern which is the entry point to the
// rest of the data.
// TODO: implement
func DecodeFile(path string) (*Pattern, error) {
p := &Pattern{}
var bit []byte
file, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println("sorry there was an error reading the file")
}
buf := bytes.NewReader(file)
err = binary.Read(buf, binary.BigEndian, &bit)
if err != nil {
fmt.Println("There was binary reading", err)
}
fmt.Println("Printer has", p)
fmt.Println("Bit has", bit)
headline := string(file[:6])
version := string(file[14:25])
bpm := binary.BigEndian.Uint32(file[45:50])
fmt.Println(headline, version, bpm)
for i := 0; i < 211; i += 25 {
test := binary.BigEndian.Uint16(file[(51 + i):(54 + i)])
namelength := int(file[54+i])
drum := string(file[(55 + i):(55 + i + namelength)])
i += namelength - 4
var beatStart int
beatStart = i + 55 + int(namelength)
var beats [16]int
for j := 0; j < (16); j++ {
beats[j] = int(file[beatStart+j])
}
fmt.Println(test, drum, "namelength:", namelength, beats)
}
return p, nil
}
// Pattern is the high level representation of the
// drum pattern contained in a .splice file.
// TODO: implement
type Pattern struct {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment