MCPcopy Create free account
hub / github.com/bspaans/python-mingus / from_shorthand

Function from_shorthand

mingus/core/intervals.py:433–486  ·  view source on GitHub ↗

Return the note on interval up or down. Examples: >>> from_shorthand('A', 'b3') 'C' >>> from_shorthand('D', '2') 'E' >>> from_shorthand('E', '2', False) 'D'

(note, interval, up=True)

Source from the content-addressed store, hash-verified

431
432
433def from_shorthand(note, interval, up=True):
434 """Return the note on interval up or down.
435
436 Examples:
437 >>> from_shorthand('A', 'b3')
438 'C'
439 >>> from_shorthand('D', '2')
440 'E'
441 >>> from_shorthand('E', '2', False)
442 'D'
443 """
444 # warning should be a valid note.
445 if not notes.is_valid_note(note):
446 return False
447
448 # [shorthand, interval function up, interval function down]
449 shorthand_lookup = [
450 ["1", major_unison, major_unison],
451 ["2", major_second, minor_seventh],
452 ["3", major_third, minor_sixth],
453 ["4", major_fourth, major_fifth],
454 ["5", major_fifth, major_fourth],
455 ["6", major_sixth, minor_third],
456 ["7", major_seventh, minor_second],
457 ]
458
459 # Looking up last character in interval in shorthand_lookup and calling that
460 # function.
461 val = False
462 for shorthand in shorthand_lookup:
463 if shorthand[0] == interval[-1]:
464 if up:
465 val = shorthand[1](note)
466 else:
467 val = shorthand[2](note)
468
469 # warning Last character in interval should be 1-7
470 if val == False:
471 return False
472
473 # Collect accidentals
474 for x in interval:
475 if x == "#":
476 if up:
477 val = notes.augment(val)
478 else:
479 val = notes.diminish(val)
480 elif x == "b":
481 if up:
482 val = notes.diminish(val)
483 else:
484 val = notes.augment(val)
485 else:
486 return val
487
488
489def is_consonant(note1, note2, include_fourths=True):

Callers

nothing calls this directly

Calls 2

augmentMethod · 0.45
diminishMethod · 0.45

Tested by

no test coverage detected