Skip to content

Commit

Permalink
reverse indexing of strings for a note; option to ignore differences …
Browse files Browse the repository at this point in the history
…in fingering when comparing
  • Loading branch information
Dmitry Jemerov committed Dec 18, 2011
1 parent 2fa2b9a commit 6729cc4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
25 changes: 24 additions & 1 deletion gtpdiff.py
Expand Up @@ -6,10 +6,33 @@ class GTPTrackComparator:
def __init__(self, track1, track2):
self.track1 = track1
self.track2 = track2
self.ignore_fingerings = True

def normalize(self, fret, string, track):
"""
:type fret: int
:type string: int
:type track: GTPTrack
"""
while string > 0:
pitch_diff = track.string_pitches[string] - track.string_pitches[string-1]
if pitch_diff >= fret:
string -= 1
fret -= pitch_diff
else:
break
return fret, string

def notes_equal(self, note1, note2):
if note1.fret != note2.fret or note1.string != note2.string or note1.duration != note2.duration:
if note1.duration != note2.duration:
return False
if note1.fret != note2.fret or note1.string != note2.string:
if self.ignore_fingerings:
fret1, string1 = self.normalize(note1.fret, note1.string, self.track1)
fret2, string2 = self.normalize(note2.fret, note2.string, self.track2)
return fret1 != fret2 or string1 != string2
else:
return False
return True

def beats_equal(self, beat1, beat2):
Expand Down
17 changes: 13 additions & 4 deletions gtpfile.py
Expand Up @@ -47,6 +47,7 @@ class GTPTrack:
def __init__(self):
self.bars = []
self.strings = 0
self.string_pitches = []

class GTPFile:
def __init__(self):
Expand Down Expand Up @@ -143,17 +144,25 @@ def load_track_info(self, track_count):
track = GTPTrack()
track.name = self.string(40)
track.strings = self.long()
self.file.seek(52, os.SEEK_CUR)
for i in range(track.strings):
track.string_pitches.append(self.long())
self.skip((7-track.strings)*4)
track.midi_port = self.long()
track.main_channel = self.long()
track.fx_channel = self.long()
track.num_frets = self.long()
track.capo_position = self.long()
track.color = self.long()
self.result.tracks.append(track)

def load_bar(self, track):
bar = GTPBar()
beats = self.long()
for i in range(beats):
self.load_beat(bar)
self.load_beat(bar, track.strings)
track.bars.append(bar)

def load_beat(self, bar):
def load_beat(self, bar, track_strings):
beat = GTPBeat()
bar.beats.append(beat)
beat_type = self.byte()
Expand All @@ -175,7 +184,7 @@ def load_beat(self, bar):
strings = self.byte()
for string in range(8):
if strings & (1 << string):
self.load_note(beat, string)
self.load_note(beat, track_strings-string)

def load_beat_special_effect(self, beat):
effect = self.byte()
Expand Down
2 changes: 1 addition & 1 deletion gtpprint.py
Expand Up @@ -20,5 +20,5 @@ def print_bar(track, bar, min_duration=None):
"""
if min_duration is None:
min_duration = bar.shortest_beat()
for string in range(track.strings, 0, -1):
for string in range(track.strings):
print_string_in_bar(bar, string, min_duration)

0 comments on commit 6729cc4

Please sign in to comment.