Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed Jan 20, 2024
1 parent 7023438 commit 0df98cd
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/musiclib/midi/pitchbend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bisect
import operator
import dataclasses
import itertools
import operator
from typing import no_type_check

import numpy as np
Expand Down Expand Up @@ -72,7 +72,7 @@ def insert_pitch_pattern(
notes=midi.notes,
pitchbend=pitchbend,
ticks_per_beat=midi.ticks_per_beat,
)
)


def make_notes_pitchbends(midi: Midi) -> dict[MidiNote, list[MidiPitch]]:
Expand Down
9 changes: 9 additions & 0 deletions tests/midi/data/notation/0/code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
header
version 2.2.1
root C3
ticks_per_beat 96

flute 17 14 10 17
flute 14 10 07 14
piano 10 07 04 10
bass 00 05 07 00
44 changes: 44 additions & 0 deletions tests/midi/data/notation/0/midi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": 1,
"ticks_per_beat": 96,
"tracks": [
[
{"type": "note_on", "time": 0, "channel": 0, "note": 48, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 48, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 53, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 53, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 55, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 55, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 48, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 48, "velocity": 100, "is_meta": false}
],
[
{"type": "note_on", "time": 0, "channel": 0, "note": 67, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 64, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 67, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 0, "channel": 0, "note": 64, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 69, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 65, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 69, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 0, "channel": 0, "note": 65, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 67, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 62, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 67, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 0, "channel": 0, "note": 62, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 67, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 64, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 67, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 0, "channel": 0, "note": 64, "velocity": 100, "is_meta": false}
],
[
{"type": "note_on", "time": 0, "channel": 0, "note": 60, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 60, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 60, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 60, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 59, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 59, "velocity": 100, "is_meta": false},
{"type": "note_on", "time": 0, "channel": 0, "note": 60, "velocity": 100, "is_meta": false},
{"type": "note_off", "time": 96, "channel": 0, "note": 60, "velocity": 100, "is_meta": false}
]
]
}
82 changes: 42 additions & 40 deletions tests/midi/notation_test.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
import pytest

from musiclib.midi import notation
from musiclib.midi.notation import IntervalEvent



@pytest.mark.parametrize('code, name', [
('flute 1 2 3 4', 'flute'),
('bass 9 8 -7 17 4 -12 0', 'bass'),
])
def test_voice_name(code, name):
assert notation.Voice(code).name == name
@pytest.mark.parametrize(
'code, channel', [
('flute 1 2 3 4', 'flute'),
('bass 9 8 -7 17 4 -12 0', 'bass'),
],
)
def test_voice_channel(code, channel):
assert notation.Voice(code).channel == channel


@pytest.mark.parametrize('code, intervals', [
(
'flute 1 2 3 4',
[
IntervalEvent(interval=1, on=0, off=96),
IntervalEvent(interval=2, on=96, off=192),
IntervalEvent(interval=3, on=192, off=288),
IntervalEvent(interval=4, on=288, off=384),
],
),
(
'flute 15 -3 .. -10 26 17 28 -- 17 29 -15 27 -8 -5 25 23',
[
IntervalEvent(interval=17, on=0, off=96),
IntervalEvent(interval=-3, on=96, off=288),
IntervalEvent(interval=-12, on=288, off=384),
IntervalEvent(interval=30, on=384, off=480),
IntervalEvent(interval=19, on=480, off=576),
IntervalEvent(interval=32, on=576, off=768),
IntervalEvent(interval=19, on=768, off=864),
IntervalEvent(interval=33, on=864, off=960),
IntervalEvent(interval=-17, on=960, off=1056),
IntervalEvent(interval=31, on=1056, off=1152),
IntervalEvent(interval=-8, on=1152, off=1248),
IntervalEvent(interval=-5, on=1248, off=1344),
IntervalEvent(interval=29, on=1344, off=1440),
IntervalEvent(interval=27, on=1440, off=1536),
],
),
])
def test_voice(code, intervals):
assert notation.Voice(code).intervals == intervals
@pytest.mark.parametrize(
'code, interval_events', [
(
'flute 1 2 3 4',
[
IntervalEvent(interval=1, on=0, off=96),
IntervalEvent(interval=2, on=96, off=192),
IntervalEvent(interval=3, on=192, off=288),
IntervalEvent(interval=4, on=288, off=384),
],
),
(
'flute 15 -3 .. -10 26 17 28 -- 17 29 -15 27 -8 -5 25 23',
[
IntervalEvent(interval=17, on=0, off=96),
IntervalEvent(interval=-3, on=96, off=288),
IntervalEvent(interval=-12, on=288, off=384),
IntervalEvent(interval=30, on=384, off=480),
IntervalEvent(interval=19, on=480, off=576),
IntervalEvent(interval=32, on=576, off=768),
IntervalEvent(interval=19, on=768, off=864),
IntervalEvent(interval=33, on=864, off=960),
IntervalEvent(interval=-17, on=960, off=1056),
IntervalEvent(interval=31, on=1056, off=1152),
IntervalEvent(interval=-8, on=1152, off=1248),
IntervalEvent(interval=-5, on=1248, off=1344),
IntervalEvent(interval=29, on=1344, off=1440),
IntervalEvent(interval=27, on=1440, off=1536),
],
),
],
)
def test_voice(code, interval_events):
assert notation.Voice(code).interval_events == interval_events


code = '''\
Expand Down

0 comments on commit 0df98cd

Please sign in to comment.