Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Created March 3, 2015 18:09
Show Gist options
  • Save RobAWilkinson/773754e01b0bcde919ea to your computer and use it in GitHub Desktop.
Save RobAWilkinson/773754e01b0bcde919ea 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, "filelength :", len(file))
fmt.Println("math :", (211-51)/25)
for i := 51; i < len(file); i += 25 {
fmt.Println("i is:", i)
test := binary.BigEndian.Uint16(file[(i):(i + 3)])
namelength := int(file[i+3])
drum := string(file[(4 + i):(4 + i + namelength)])
var beatStart int
beatStart = i + 4 + 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)
i += namelength - 4
}
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