OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 |
| 3 from __future__ import division |
| 4 |
2 import inspect | 5 import inspect |
3 import sys | 6 import sys |
4 import re | 7 import re |
5 import math | 8 import math |
6 import lilylib as ly | 9 import lilylib as ly |
7 import warnings | 10 import warnings |
8 import utilities | 11 import utilities |
9 | 12 |
10 _ = ly._ | 13 _ = ly._ |
11 | 14 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 c.normalize () | 392 c.normalize () |
390 | 393 |
391 target_st = self.semitones() + interval.semitones() | 394 target_st = self.semitones() + interval.semitones() |
392 c.alteration += target_st - c.semitones() | 395 c.alteration += target_st - c.semitones() |
393 return c | 396 return c |
394 | 397 |
395 def normalize (c): | 398 def normalize (c): |
396 while c.step < 0: | 399 while c.step < 0: |
397 c.step += 7 | 400 c.step += 7 |
398 c.octave -= 1 | 401 c.octave -= 1 |
399 c.octave += c.step / 7 | 402 c.octave += c.step // 7 |
400 c.step = c.step % 7 | 403 c.step = c.step % 7 |
401 | 404 |
402 def lisp_expression (self): | 405 def lisp_expression (self): |
403 return '(ly:make-pitch %d %d %d)' % (self.octave, | 406 return '(ly:make-pitch %d %d %d)' % (self.octave, |
404 self.step, | 407 self.step, |
405 self.alteration) | 408 self.alteration) |
406 | 409 |
407 def copy (self): | 410 def copy (self): |
408 p = Pitch () | 411 p = Pitch () |
409 p.alteration = self.alteration | 412 p.alteration = self.alteration |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 def relative_pitch (self): | 457 def relative_pitch (self): |
455 global previous_pitch | 458 global previous_pitch |
456 if not previous_pitch: | 459 if not previous_pitch: |
457 previous_pitch = self | 460 previous_pitch = self |
458 return self.absolute_pitch () | 461 return self.absolute_pitch () |
459 previous_pitch_steps = previous_pitch.octave * 7 + previous_pitch.step | 462 previous_pitch_steps = previous_pitch.octave * 7 + previous_pitch.step |
460 this_pitch_steps = self.octave * 7 + self.step | 463 this_pitch_steps = self.octave * 7 + self.step |
461 pitch_diff = (this_pitch_steps - previous_pitch_steps) | 464 pitch_diff = (this_pitch_steps - previous_pitch_steps) |
462 previous_pitch = self | 465 previous_pitch = self |
463 if pitch_diff > 3: | 466 if pitch_diff > 3: |
464 return "'" * ((pitch_diff + 3) / 7) | 467 return "'" * ((pitch_diff + 3) // 7) |
465 elif pitch_diff < -3: | 468 elif pitch_diff < -3: |
466 return "," * ((-pitch_diff + 3) / 7) | 469 return "," * ((-pitch_diff + 3) // 7) |
467 else: | 470 else: |
468 return "" | 471 return "" |
469 | 472 |
470 def ly_expression (self): | 473 def ly_expression (self): |
471 str = self.ly_step_expression () | 474 str = self.ly_step_expression () |
472 if relative_pitches and not self._force_absolute_pitch: | 475 if relative_pitches and not self._force_absolute_pitch: |
473 str += self.relative_pitch () | 476 str += self.relative_pitch () |
474 else: | 477 else: |
475 str += self.absolute_pitch () | 478 str += self.absolute_pitch () |
476 return str | 479 return str |
(...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2514 expr = test_expr() | 2517 expr = test_expr() |
2515 expr.set_start (Rational (0)) | 2518 expr.set_start (Rational (0)) |
2516 print expr.ly_expression() | 2519 print expr.ly_expression() |
2517 start = Rational (0, 4) | 2520 start = Rational (0, 4) |
2518 stop = Rational (4, 2) | 2521 stop = Rational (4, 2) |
2519 def sub(x, start=start, stop=stop): | 2522 def sub(x, start=start, stop=stop): |
2520 ok = x.start >= start and x.start + x.get_length() <= stop | 2523 ok = x.start >= start and x.start + x.get_length() <= stop |
2521 return ok | 2524 return ok |
2522 | 2525 |
2523 print expr.lisp_sub_expression(sub) | 2526 print expr.lisp_sub_expression(sub) |
OLD | NEW |