|
20 | 20 | import binascii
|
21 | 21 | import collections
|
22 | 22 | import numbers
|
| 23 | +import operator |
23 | 24 | import copy
|
24 | 25 | import math
|
25 | 26 |
|
@@ -434,6 +435,41 @@ def _node_error(self, attribute):
|
434 | 435 | 'Cannot set {attribute} without a time specification.'.format(
|
435 | 436 | attribute=attribute))
|
436 | 437 |
|
| 438 | + def _comparison(self, other, comparison): |
| 439 | + if isinstance(other, Time): |
| 440 | + return comparison(self.note, other.note) |
| 441 | + elif isinstance(other, collections.Iterable): |
| 442 | + if len(other) == 3: |
| 443 | + time = Time(specification=self.specification) |
| 444 | + time.triple = other |
| 445 | + return comparison(self.note, time.note) |
| 446 | + elif isinstance(other, numbers.Number): |
| 447 | + return comparison(self.note, other) |
| 448 | + elif other == None: |
| 449 | + if comparison == operator.eq: |
| 450 | + return False |
| 451 | + elif comparison == operator.ne: |
| 452 | + return True |
| 453 | + return NotImplemented |
| 454 | + |
| 455 | + def __lt__(self, other): |
| 456 | + return self._comparison(other, operator.lt) |
| 457 | + |
| 458 | + def __le__(self, other): |
| 459 | + return self._comparison(other, operator.le) |
| 460 | + |
| 461 | + def __eq__(self, other): |
| 462 | + return self._comparison(other, operator.eq) |
| 463 | + |
| 464 | + def __ne__(self, other): |
| 465 | + return self._comparison(other, operator.ne) |
| 466 | + |
| 467 | + def __ge__(self, other): |
| 468 | + return self._comparison(other, operator.ge) |
| 469 | + |
| 470 | + def __gt__(self, other): |
| 471 | + return self._comparison(other, operator.gt) |
| 472 | + |
437 | 473 | def __repr__(self):
|
438 | 474 | return str(self)
|
439 | 475 |
|
@@ -1319,7 +1355,7 @@ def meta(event):
|
1319 | 1355 | def track(event):
|
1320 | 1356 | return event.track
|
1321 | 1357 | def time(event):
|
1322 |
| - return event.time.note |
| 1358 | + return event.time |
1323 | 1359 | super().sort(key=meta, reverse=reverse)
|
1324 | 1360 | super().sort(key=track, reverse=reverse)
|
1325 | 1361 | super().sort(key=time, reverse=reverse)
|
|
0 commit comments