| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from mido.midifiles.units import bpm2tempo, second2tick, tempo2bpm, tick2second |
| 6 |
|
| 7 |
|
| 8 |
def test_tempo2bpm(): |
| 9 |
|
| 10 |
assert tempo2bpm(500000) == 120 |
| 11 |
assert tempo2bpm(1000000) == 60 |
| 12 |
|
| 13 |
|
| 14 |
assert tempo2bpm(1000000, time_signature=(4, 4)) == 60 |
| 15 |
|
| 16 |
assert tempo2bpm(500000, time_signature=(4, 4)) == 120 |
| 17 |
assert tempo2bpm(500000, time_signature=(3, 4)) == 120 |
| 18 |
|
| 19 |
|
| 20 |
assert tempo2bpm(500000, time_signature=(2, 2)) == 60 |
| 21 |
|
| 22 |
assert tempo2bpm(250000, time_signature=(2, 2)) == 120 |
| 23 |
assert tempo2bpm(250000, time_signature=(3, 2)) == 120 |
| 24 |
|
| 25 |
|
| 26 |
assert tempo2bpm(2000000, time_signature=(8, 8)) == 60 |
| 27 |
|
| 28 |
assert tempo2bpm(1000000, time_signature=(8, 8)) == 120 |
| 29 |
assert tempo2bpm(1000000, time_signature=(8, 8)) == 120 |
| 30 |
|
| 31 |
|
| 32 |
def test_bpm2tempo(): |
| 33 |
|
| 34 |
assert bpm2tempo(60) == 1000000 |
| 35 |
assert bpm2tempo(120) == 500000 |
| 36 |
|
| 37 |
|
| 38 |
assert bpm2tempo(60, time_signature=(4, 4)) == 1000000 |
| 39 |
|
| 40 |
assert bpm2tempo(120, time_signature=(4, 4)) == 500000 |
| 41 |
assert bpm2tempo(120, time_signature=(3, 4)) == 500000 |
| 42 |
|
| 43 |
|
| 44 |
assert bpm2tempo(60, time_signature=(2, 2)) == 500000 |
| 45 |
|
| 46 |
assert bpm2tempo(120, time_signature=(2, 2)) == 250000 |
| 47 |
assert bpm2tempo(120, time_signature=(3, 2)) == 250000 |
| 48 |
|
| 49 |
|
| 50 |
assert bpm2tempo(60, time_signature=(8, 8)) == 2000000 |
| 51 |
|
| 52 |
assert bpm2tempo(120, time_signature=(8, 8)) == 1000000 |
| 53 |
assert bpm2tempo(120, time_signature=(8, 8)) == 1000000 |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
def test_tick2second(): |
| 59 |
|
| 60 |
assert tick2second(1, ticks_per_beat=100, tempo=500000) == 0.005 |
| 61 |
assert tick2second(2, ticks_per_beat=100, tempo=100000) == 0.002 |
| 62 |
|
| 63 |
|
| 64 |
def test_second2tick(): |
| 65 |
|
| 66 |
assert second2tick(0.001, ticks_per_beat=100, tempo=500000) == 0 |
| 67 |
assert second2tick(0.004, ticks_per_beat=100, tempo=500000) == 1 |
| 68 |
assert second2tick(0.005, ticks_per_beat=100, tempo=500000) == 1 |
| 69 |
assert second2tick(0.0015, ticks_per_beat=100, tempo=100000) == 2 |
| 70 |
assert second2tick(0.0025, ticks_per_beat=100, tempo=100000) == 2 |