omusic package
Submodules
omusic.chord module
Utilities that construct chords.
- omusic.chord.triad(base_key: str, progression: list[int], add: int | list[int] = [], sus: int | list[int] = [], sharp: int | list[int] = [], flat: int | list[int] = [], intervals: str | list[str] = [], order: int = 0) list[str][source]
Construct a triad.
- Parameters:
add – Positions of notes in scale to add, 0 indexed.
sus – Positions of notes in scale to remove, 0 indexed
intervals – Positions of notes in scale to remove
- omusic.chord.seventh(base_key: str, progression: list[int], type: Literal['major'] | Literal['minor'] | Literal['augmented'] | Literal['diminished'] | None = None, add: int | list[int] = [], sub: int | list[int] = [], intervals: str | list[str] = [], order: int = 0) list[str][source]
omusic.guitar module
Utilities that visualise notes on a fretboard.
- omusic.guitar.notes_on_string(start: int, capo: int, length: int) list[int][source]
Return a list of
lengthnotes on a string that begins with thestartth note at capocapo.
- omusic.guitar.notes_on_fretboard(capo: int, length: int, tuning: list[int]) list[list[int]][source]
Return a matrix of notes for all strings on a guitar for the given
tuning.The item at [i][j] is the jth note on the ith string … I think.
- omusic.guitar.notes_of_interest(notes: list[str], octave_matrix: list[list[int]], strict: bool = False) list[list[int | None]][source]
Given a matrix of notes, replace items that are not in the given scale with None, then return the result.
Use to visualise chords.
omusic.midi module
Utilities that play MIDI notes.
- class omusic.midi.Instrument[source]
Bases:
IntEnumInstrument codes implemented with reference to the General MIDI Level 1 specification (source).
- AcousticGrandPiano = 1
- BrightAcousticPiano = 2
- ElectricGrandPiano = 3
- HonkyTonkPiano = 4
- ElectricPiano1 = 5
- ElectricPiano2 = 6
- Harpsichord = 7
- Clavi = 8
- Celesta = 9
- Glockenspiel = 10
- MusicBox = 11
- Vibraphone = 12
- Marimba = 13
- Xylophone = 14
- TubularBells = 15
- Dulcimer = 16
- DrawbarOrgan = 17
- PercussiveOrgan = 18
- RockOrgan = 19
- ChurchOrgan = 20
- ReedOrgan = 21
- Accordion = 22
- Harmonica = 23
- TangoAccordion = 24
- AcousticGuitarNylon = 25
- AcousticGuitarSteel = 26
- ElectricGuitarJazz = 27
- ElectricGuitarClean = 28
- ElectricGuitarMuted = 29
- OverdrivenGuitar = 30
- DistortionGuitar = 31
- Guitarharmonics = 32
- AcousticBass = 33
- ElectricBassFinger = 34
- ElectricBassPick = 35
- FretlessBass = 36
- SlapBass1 = 37
- SlapBass2 = 38
- SynthBass1 = 39
- SynthBass2 = 40
- Violin = 41
- Viola = 42
- Cello = 43
- Contrabass = 44
- TremoloStrings = 45
- PizzicatoStrings = 46
- OrchestralHarp = 47
- Timpani = 48
- StringEnsemble1 = 49
- StringEnsemble2 = 50
- SynthStrings1 = 51
- SynthStrings2 = 52
- ChoirAahs = 53
- VoiceOohs = 54
- SynthVoice = 55
- OrchestraHit = 56
- Trumpet = 57
- Trombone = 58
- Tuba = 59
- MutedTrumpet = 60
- FrenchHorn = 61
- BrassSection = 62
- SynthBrass1 = 63
- SynthBrass2 = 64
- SopranoSax = 65
- AltoSax = 66
- TenorSax = 67
- BaritoneSax = 68
- Oboe = 69
- EnglishHorn = 70
- Bassoon = 71
- Clarinet = 72
- Piccolo = 73
- Flute = 74
- Recorder = 75
- PanFlute = 76
- BlownBottle = 77
- Shakuhachi = 78
- Whistle = 79
- Ocarina = 80
- Lead1Square = 81
- Lead2Sawtooth = 82
- Lead3Calliope = 83
- Lead4Chiff = 84
- Lead5Charang = 85
- Lead6Voice = 86
- Lead7Fifths = 87
- Lead8BassPlusLead = 88
- Pad1Newage = 89
- Pad2Warm = 90
- Pad3Polysynth = 91
- Pad4Choir = 92
- Pad5Bowed = 93
- Pad6Metallic = 94
- Pad7Halo = 95
- Pad8Sweep = 96
- FX1Rain = 97
- FX2Soundtrack = 98
- FX3Crystal = 99
- FX4Atmosphere = 100
- FX5Brightness = 101
- FX6Goblins = 102
- FX7Echoes = 103
- FX8SciFi = 104
- Sitar = 105
- Banjo = 106
- Shamisen = 107
- Koto = 108
- Kalimba = 109
- Bagpipe = 110
- Fiddle = 111
- Shanai = 112
- TinkleBell = 113
- Agogo = 114
- SteelDrums = 115
- Woodblock = 116
- TaikoDrum = 117
- MelodicTom = 118
- SynthDrum = 119
- ReverseCymbal = 120
- GuitarFretNoise = 121
- BreathNoise = 122
- Seashore = 123
- BirdTweet = 124
- TelephoneRing = 125
- Helicopter = 126
- Applause = 127
- Gunshot = 128
- omusic.midi.play_notes(output: Output, pitches: Sequence[int], duration: float, gap: float, velocity: int)[source]
- omusic.midi.play(player: Player, sound: str | list[str], duration: float = 2, gap: float = 0, velocity: int = 64) None[source]
- omusic.midi.change_instrument(player: Player, instrument: Instrument) None[source]
omusic.modes module
Patterns that are useful for constructing scales and chords.
A scale is constructed with a note and one such pattern (for example, C major consists of the note C as well as the 2nd, 4th, 5th … and so on, notes from C.) This pattern is the mode (or key) of the scale.
Whereas scales (see scale) are constructed by picking notes in a music
space, chords are (see chord) constructed by picking notes from a scale.
Both (scale) and (chord) can use constants defined
in this module.
omusic.scale module
Utilities that construct scales.
Module contents
In this text, a number can mean one of three things:
A note (2 for “Re”, or D).
An interval (2 for “two notes from the previous note”).
An offset (“two notes from the first note”).
To differentiate these, use type “aliases” defined in the following cell instead of int.
- omusic.note_i2s(note: Note | None) str[source]
- omusic.note_i2s(note: Sequence[Note | None]) list[str]
Return either a string or a list of strings that represents note(s) in
note.
- omusic.note_s2i(name: str, solfege: bool = False) Note[source]
- omusic.note_s2i(name: list[str], solfege: bool = False) list[Note]
Return either an integer or a list of notes that represents note(s) in
name.
- omusic.NOTES = ['C0', 'C#0', 'D0', 'D#0', 'E0', 'F0', 'F#0', 'G0', 'G#0', 'A0', 'A#0', 'B0', 'C1', 'C#1', 'D1', 'D#1', 'E1', 'F1', 'F#1', 'G1', 'G#1', 'A1', 'A#1', 'B1', 'C2', 'C#2', 'D2', 'D#2', 'E2', 'F2', 'F#2', 'G2', 'G#2', 'A2', 'A#2', 'B2', 'C3', 'C#3', 'D3', 'D#3', 'E3', 'F3', 'F#3', 'G3', 'G#3', 'A3', 'A#3', 'B3', 'C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4', 'C5', 'C#5', 'D5', 'D#5', 'E5', 'F5', 'F#5', 'G5', 'G#5', 'A5', 'A#5', 'B5', 'C6', 'C#6', 'D6', 'D#6', 'E6', 'F6', 'F#6', 'G6', 'G#6', 'A6', 'A#6', 'B6', 'C7', 'C#7', 'D7', 'D#7', 'E7', 'F7', 'F#7', 'G7', 'G#7', 'A7', 'A#7', 'B7', 'C8', 'C#8', 'D8', 'D#8', 'E8', 'F8', 'F#8', 'G8', 'G#8', 'A8', 'A#8', 'B8', 'C9', 'C#9', 'D9', 'D#9', 'E9', 'F9', 'F#9', 'G9', 'G#9', 'A9', 'A#9', 'B9', 'C10', 'C#10', 'D10', 'D#10', 'E10', 'F10', 'F#10', 'G10']
Map of each apartness to a name. The entry apartness: (major/minor, number) means apartness apartness is the major/minor number th.
- omusic.interval_i2s(key_num: int) list[str][source]
Map an apartness to the appropriate name according to
INTERVALS.
- omusic.name_interval(note_from: str, note_to: str) str[source]
Map an apartness to the appropriate name according to
INTERVALS.
- omusic.invert(arg: str) str[source]
- omusic.invert(arg: Note) Note
Invert an interval. Or a note.
Works with both because taking the modular complement happens to have the same effect on both.