def test_key_invalid(): with pytest.raises(iso.UnknownNoteName): a = iso.Key("X", "major") with pytest.raises(iso.UnknownNoteName): a = iso.Key("H", "minor") with pytest.raises(iso.UnknownScaleName): a = iso.Key("C", "mundo")
def test_key_eq(): a = iso.Key() b = iso.Key(0, iso.Scale([0, 2, 4, 5, 7, 9, 11])) assert a == b c = iso.Key(0, iso.Scale([0, 2, 3, 5, 7, 9, 11])) assert a != c d = iso.Key(1, iso.Scale([0, 2, 4, 5, 7, 9, 11])) assert a != d
def test_pglobals(): with pytest.raises(KeyError): iso.Globals.get("key") iso.Globals.set("key", iso.Key("C", "major")) assert iso.Globals.get("key") == iso.Key("C", "major") pattern = iso.PGlobals("key") assert next(pattern) == iso.Key("C", "major") assert next(pattern) == iso.Key("C", "major")
def test_event_key(dummy_timeline): dummy_timeline.schedule({ iso.EVENT_DEGREE: iso.PSequence([0, 1, 2, 3], 1), iso.EVENT_KEY: iso.PSequence([iso.Key("C", "major"), iso.Key("F", "major")]), iso.EVENT_TRANSPOSE: 12 }) dummy_timeline.run() assert dummy_timeline.output_device.events == [ [0, 'note_on', 12, 64, 0], [1, 'note_off', 12, 0], [1, 'note_on', 19, 64, 0], [2, 'note_off', 19, 0], [2, 'note_on', 16, 64, 0], [3, 'note_off', 16, 0], [3, 'note_on', 22, 64, 0], [4, 'note_off', 22, 0] ]
def test_key_get(): a = iso.Key("C", "major") assert a.get(0) == a[0] == 0 assert a.get(1) == a[1] == 2 assert a.get(2) == a[2] == 4 assert a.get(7) == a[7] == 12 assert a.get(-1) == a[-1] == -1
def test_key_contains(): a = iso.Key("C", "major") assert 0 in a assert 1 not in a assert 2 in a assert 3 not in a assert 4 in a assert 12 in a assert 13 not in a assert -1 in a assert None in a
def test_key_nearest_note(): a = iso.Key("C", "minor") assert a.nearest_note(0) == 0 assert a.nearest_note(1) == 0 assert a.nearest_note(2) == 2 assert a.nearest_note(3) == 3 assert a.nearest_note(4) == 3 assert a.nearest_note(5) == 5 assert a.nearest_note(6) == 5 assert a.nearest_note(7) == 7 assert a.nearest_note(8) == 8 assert a.nearest_note(9) == 8 assert a.nearest_note(10) == 11 assert a.nearest_note(11) == 11
#!/usr/bin/env python3 #------------------------------------------------------------------------ # isobar: ex-static-pattern # # Bind a chord sequence to a static sequence, which is then referenced # in other patterns. #------------------------------------------------------------------------ import isobar as iso key_sequence = iso.PSequence([ iso.Key("C", "minor"), iso.Key("G", "minor"), iso.Key("Bb", "major"), iso.Key("F", "major"), ]) key = iso.PStaticPattern(key_sequence, 4) timeline = iso.Timeline(120) timeline.schedule({"degree": 0, "key": key, "octave": 3}) timeline.schedule({ "degree": iso.PCreep(iso.PWhite(0, 6), 2, 2, 3), "key": key, "octave": 6, "duration": 0.25 }) timeline.run()
# # Use simple permutations to generate intertwining musical structures. #------------------------------------------------------------------------ import isobar as iso import random import logging logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s") #------------------------------------------------------------------------ # Create a pitch line comprised of multiple permutations on a pelog scale #------------------------------------------------------------------------ ppitch = iso.PShuffle([random.randint(-6, 6) for n in range(6)]) ppitch = iso.PPermut(ppitch) ppitch = iso.PDegree(ppitch, iso.Key("F#", "pelog")) #------------------------------------------------------------------------ # Create permuted sets of durations and amplitudes. # Different lengths mean poly-combinations. #------------------------------------------------------------------------ pdur = iso.PShuffle([1, 1, 2, 2, 4], 1) pdur = iso.PPermut(pdur) / 4 pamp = iso.PShuffle([10, 15, 20, 35], 2) pamp = iso.PPermut(pamp) #------------------------------------------------------------------------ # Schedule on a 60bpm timeline and send to MIDI output #------------------------------------------------------------------------ timeline = iso.Timeline(60)
def test_pnearest(): a = iso.PNearestNoteInKey(iso.PSequence([0, 1, 2, 3, -1, None, 12.5], 1), iso.Key("C", "major")) assert list(a) == [0, 0, 2, 2, -1, None, 12]
def test_pfilterbykey(): a = iso.PFilterByKey(iso.PSequence([0, 1, 2, 3, -1, None, 2], 1), iso.Key("C", "major")) assert list(a) == [0, None, 2, None, -1, None, 2]
def test_psequence_keys(): a = iso.PSequence([iso.Key("C", "major"), iso.Key("F", "minor")], 1) assert list(a) == [iso.Key("C", "major"), iso.Key("F", "minor")]
def test_key_distance(): a = iso.Key("C", "minor") b = iso.Key("C", "major") assert a.distance(b) == 2
def test_key_defaults(): a = iso.Key() assert a.get(0) == 0 assert a.get(1) == 2
def test_key_semitones(): a = iso.Key("C", "minor") assert a.semitones == [0, 2, 3, 5, 7, 8, 11]
#!/usr/bin/env python3 #------------------------------------------------------------------------ # ex-midifile-write: # # Simple example of writing to a MIDI file in real time. #------------------------------------------------------------------------ import isobar as iso from isobar.io import MidiFileOutputDevice import logging logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] %(message)s") key = iso.Key("C", "major") filename = "output.mid" output = MidiFileOutputDevice(filename) timeline = iso.Timeline(iso.MAX_CLOCK_RATE, output_device=output) timeline.stop_when_done = True timeline.schedule({ "note": iso.PDegree(iso.PSequence([ 0, 1, 2, 4 ], 4), key), "octave": 5, "gate": iso.PSequence([ 0.5, 1, 2, 1 ]), "amplitude": iso.PSequence([ 100, 80, 60, 40], 4), "duration": 1.0 }) timeline.schedule({