Skip to content

Commit fad63c8

Browse files
committed
Updated README and added _BaseNote
1 parent 651b329 commit fad63c8

3 files changed

Lines changed: 39 additions & 99 deletions

File tree

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Assuming your .chart file is named "notes.chart"...
2323
>>> import chparse
2424
>>> with open('notes.chart') as chartfile:
2525
... chart = chparse.load(chartfile)
26-
>>> chart.instruments[chparse.EXPERT][chparse.GUITAR].notes[0]
26+
>>> chart.instruments[chparse.EXPERT][chparse.GUITAR][0]
2727
<Note: 0 = N 3 0 (<Flags.NONE: 0>)>

chparse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
>>> import chparse
2525
>>> with open('notes.chart') as chartfile:
2626
... chart = chparse.load(chartfile)
27-
>>> chart.instruments[chparse.EXPERT][chparse.GUITAR].notes[0]
27+
>>> chart.instruments[chparse.EXPERT][chparse.GUITAR][0]
2828
<Note: 0 = N 3 0 (<Flags.NONE: 0>)>
2929
"""
3030
from .parse import load, dump

chparse/note.py

Lines changed: 37 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
"""Contains the Note class."""
22
from . import flags as _flags
33

4-
class Note(object):
5-
"""Represents a single note - i.e. 0 = X 0 0"""
4+
class _BaseNote(object):
5+
"""Represents anything resembling a note."""
66
time = 0
7+
8+
def __cmp__(self, other):
9+
if not isinstance(other, _BaseNote):
10+
raise TypeError('Cannot compare Note with {.__name__}'
11+
.format(type(other)))
12+
return (-1
13+
if self.time < other.time
14+
else (1
15+
if self.time > other.time
16+
else 0
17+
)
18+
)
19+
20+
def __lt__(self, other):
21+
return self.__cmp__(other) < 0
22+
23+
def __le__(self, other):
24+
return self.__cmp__(other) <= 0
25+
26+
def __eq__(self, other):
27+
return self.__cmp__(other) == 0
28+
29+
def __ne__(self, other):
30+
return self.__cmp__(other) != 0
31+
32+
def __gt__(self, other):
33+
return self.__cmp__(other) > 0
34+
35+
def __ge__(self, other):
36+
return self.__cmp__(other) >= 0
37+
38+
class Note(_BaseNote):
39+
"""Represents a single note - i.e. 0 = X 0 0"""
740
kind = _flags.NOTE
841
fret = 0
942
length = 0
@@ -55,36 +88,6 @@ def __str__(self):
5588
result += '\n' + result2
5689
return result
5790

58-
def __cmp__(self, other):
59-
if not isinstance(other, (Note, Event, SyncEvent)):
60-
raise TypeError('Cannot compare Note with {.__name__}'
61-
.format(type(other)))
62-
return (-1
63-
if self.time < other.time
64-
else (1
65-
if self.time > other.time
66-
else 0
67-
)
68-
)
69-
70-
def __lt__(self, other):
71-
return self.__cmp__(other) < 0
72-
73-
def __le__(self, other):
74-
return self.__cmp__(other) <= 0
75-
76-
def __eq__(self, other):
77-
return self.__cmp__(other) == 0
78-
79-
def __ne__(self, other):
80-
return self.__cmp__(other) != 0
81-
82-
def __gt__(self, other):
83-
return self.__cmp__(other) > 0
84-
85-
def __ge__(self, other):
86-
return self.__cmp__(other) >= 0
87-
8891
@property
8992
def is_tap(self):
9093
"""Return whether this Note is a tap note."""
@@ -109,9 +112,8 @@ def is_forced(self):
109112
else (_flags.FORCED in self.flags)
110113
)
111114

112-
class Event(object): #pylint: disable=too-few-public-methods
115+
class Event(_BaseNote): #pylint: disable=too-few-public-methods
113116
"""Represents the special E note for events."""
114-
time = 0
115117
event = ''
116118

117119
def __init__(self, time, evt):
@@ -124,40 +126,8 @@ def __repr__(self):
124126
def __str__(self):
125127
return ' {} = E {}'.format(self.time, self.event)
126128

127-
def __cmp__(self, other):
128-
if not isinstance(other, (Note, Event, SyncEvent)):
129-
raise TypeError('Cannot compare Event with {.__name__}'
130-
.format(type(other)))
131-
return (-1
132-
if self.time < other.time
133-
else (1
134-
if self.time > other.time
135-
else 0
136-
)
137-
)
138-
139-
def __lt__(self, other):
140-
return self.__cmp__(other) < 0
141-
142-
def __le__(self, other):
143-
return self.__cmp__(other) <= 0
144-
145-
def __eq__(self, other):
146-
return self.__cmp__(other) == 0
147-
148-
def __ne__(self, other):
149-
return self.__cmp__(other) != 0
150-
151-
def __gt__(self, other):
152-
return self.__cmp__(other) > 0
153-
154-
def __ge__(self, other):
155-
return self.__cmp__(other) >= 0
156-
157-
158-
class SyncEvent(object):
129+
class SyncEvent(_BaseNote):
159130
"""Represents the special TS and B notes in the SyncTrack instrument."""
160-
time = 0
161131
kind = _flags.BPM
162132
value = 0
163133

@@ -170,33 +140,3 @@ def __repr__(self):
170140

171141
def __str__(self):
172142
return ' {} = {} {}'.format(self.time, self.kind.value, self.value)
173-
174-
def __cmp__(self, other):
175-
if not isinstance(other, (Note, Event, SyncEvent)):
176-
raise TypeError('Cannot compare SyncEvent with {.__name__}'
177-
.format(type(other)))
178-
return (-1
179-
if self.time < other.time
180-
else (1
181-
if self.time > other.time
182-
else 0
183-
)
184-
)
185-
186-
def __lt__(self, other):
187-
return self.__cmp__(other) < 0
188-
189-
def __le__(self, other):
190-
return self.__cmp__(other) <= 0
191-
192-
def __eq__(self, other):
193-
return self.__cmp__(other) == 0
194-
195-
def __ne__(self, other):
196-
return self.__cmp__(other) != 0
197-
198-
def __gt__(self, other):
199-
return self.__cmp__(other) > 0
200-
201-
def __ge__(self, other):
202-
return self.__cmp__(other) >= 0

0 commit comments

Comments
 (0)