Skip to content

Commit

Permalink
Merge pull request #1 from chr15m/master
Browse files Browse the repository at this point in the history
Small fixes for Linux, sample data, test script.
  • Loading branch information
ramen committed Nov 22, 2016
2 parents 1a5692b + d9c6dd8 commit 2f4812f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
23 changes: 23 additions & 0 deletions pytrax.py
@@ -0,0 +1,23 @@
from pytrax import impulsetracker

if __name__ == "__main__":
import sys
import pprint
if len(sys.argv) > 1:
info = impulsetracker.parse_file(sys.argv[1], with_samples=True, with_instruments=True, with_patterns=True)
instruments = info.pop("instruments", None)
samples = info.pop("samples", None)
patterns = info.pop("patterns", None)

for i in info:
print i, "=>", info[i]
print
if instruments:
print len(instruments), "instruments"
if samples:
print len(samples), "samples"
if patterns:
print len(patterns), "patterns"
else:
print "usage:", sys.argv[0], "FILE.it"

28 changes: 19 additions & 9 deletions pytrax/impulsetracker.py
Expand Up @@ -3,10 +3,10 @@

import struct

IT_HEADER = '4x26s2x8H5BxHL4x128B'
IT_HEADER_INS = '4x12sx3BH6BHBx26s6x120H'
IT_HEADER_SMP = '4x12sx3B26s2B7L4B'
IT_HEADER_PAT = '2H4x'
IT_HEADER = '<4x26s2x8H5BxHL4x128B'
IT_HEADER_INS = '<4x12sx3BH6BHBx26s6x120H'
IT_HEADER_SMP = '<4x12sx3B26s2B7L4B'
IT_HEADER_PAT = '<2H4x'

def parse_file(filename,
with_instruments=False,
Expand Down Expand Up @@ -42,12 +42,12 @@ def parse(file,
'pansep': data[13],
'pantable': data[16:80],
'voltable': data[80:144],
'orders': struct.unpack('%dB' % data[1], file.read(data[1])),
'orders': struct.unpack('<%dB' % data[1], file.read(data[1])),
}
insoffs = struct.unpack('%dL' % data[2], file.read(data[2] * 4))
smpoffs = struct.unpack('%dL' % data[3], file.read(data[3] * 4))
patoffs = struct.unpack('%dL' % data[4], file.read(data[4] * 4))

insoffs = struct.unpack('<%dL' % data[2], file.read(data[2] * 4))
smpoffs = struct.unpack('<%dL' % data[3], file.read(data[3] * 4))
patoffs = struct.unpack('<%dL' % data[4], file.read(data[4] * 4))

info['message'] = ''
if data[8] & 0x01:
Expand All @@ -57,6 +57,10 @@ def parse(file,
if with_instruments: info['instruments'] = _get_instruments(file, insoffs)
if with_samples: info['samples'] = _get_samples(file, smpoffs)
if with_patterns: info['patterns'] = _get_patterns(file, patoffs)

# add sample data to samples
if not (info.has_key('instruments') and info["instruments"]) and with_samples:
_load_sample_data(file, info['samples'])

return info

Expand Down Expand Up @@ -121,6 +125,12 @@ def _get_samples(file, offs):

return result

def _load_sample_data(file, samples):
for s in samples:
file.seek(s['offset'])
s['sampledata'] = file.read(s['length'])
return samples

def _get_patterns(file, offs):
result = []

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from distutils.core import setup

setup(name='pytrax',
version='0.1',
version='0.2',
description='Impulse Tracker parser',
author='Dave Benjamin',
author_email='dave@ramenlabs.com',
Expand Down

0 comments on commit 2f4812f

Please sign in to comment.