Ejemplo n.º 1
0
def test_to_jams():

    data_home = 'tests/resources/mir_datasets/Beatles'
    track = beatles.Track('0111', data_home=data_home)
    jam = track.to_jams()

    beats = jam.search(namespace='beat')[0]['data']
    assert [beat.time for beat in beats] == [
        13.249,
        13.959,
        14.416,
        14.965,
        15.453,
        15.929,
        16.428,
    ]
    assert [beat.duration
            for beat in beats] == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    assert [beat.value for beat in beats] == [2, 3, 4, 1, 2, 3, 4]
    assert [beat.confidence for beat in beats] == [
        None,
        None,
        None,
        None,
        None,
        None,
        None,
    ]

    segments = jam.search(namespace='segment')[0]['data']
    assert [segment.time for segment in segments] == [0.0, 0.465]
    assert [segment.duration for segment in segments] == [0.465, 14.466]
    assert [segment.value for segment in segments] == ['silence', 'intro']
    assert [segment.confidence for segment in segments] == [None, None]

    chords = jam.search(namespace='chord')[0]['data']
    assert [chord.time for chord in chords] == [0.0, 4.586464, 6.98973]
    assert [chord.duration for chord in chords] == [
        0.497838,
        2.4032659999999995,
        2.995374,
    ]
    assert [chord.value for chord in chords] == ['N', 'E:min', 'G']
    assert [chord.confidence for chord in chords] == [None, None, None]

    keys = jam.search(namespace='key')[0]['data']
    assert [key.time for key in keys] == [0.0]
    assert [key.duration for key in keys] == [119.333]
    assert [key.value for key in keys] == ['E']
    assert [key.confidence for key in keys] == [None]

    assert jam['file_metadata']['title'] == '11_-_Do_You_Want_To_Know_A_Secret'
    assert jam['file_metadata']['artist'] == 'The Beatles'
Ejemplo n.º 2
0
def test_track():
    default_trackid = '0111'
    data_home = 'tests/resources/mir_datasets/Beatles'
    track = beatles.Track(default_trackid, data_home=data_home)

    expected_attributes = {
        'audio_path': 'tests/resources/mir_datasets/Beatles/' +
        'audio/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.wav',
        'beats_path': 'tests/resources/mir_datasets/Beatles/' +
        'annotations/beat/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.txt',
        'chords_path': 'tests/resources/mir_datasets/Beatles/' +
        'annotations/chordlab/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab',
        'keys_path': 'tests/resources/mir_datasets/Beatles/' +
        'annotations/keylab/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab',
        'sections_path': 'tests/resources/mir_datasets/Beatles/' +
        'annotations/seglab/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab',
        'title': '11_-_Do_You_Want_To_Know_A_Secret',
        'track_id': '0111',
    }

    expected_property_types = {
        'beats': utils.BeatData,
        'chords': utils.ChordData,
        'key': utils.KeyData,
        'sections': utils.SectionData,
    }

    run_track_tests(track, expected_attributes, expected_property_types)

    audio, sr = track.audio
    assert sr == 44100, 'sample rate {} is not 44100'.format(sr)
    assert audio.shape == (44100 *
                           2, ), 'audio shape {} was not (88200,)'.format(
                               audio.shape)

    track = beatles.Track('10212')
    assert track.beats is None, 'expected track.beats to be None, got {}'.format(
        track.beats)
    assert track.key is None, 'expected track.key to be None, got {}'.format(
        track.key)
Ejemplo n.º 3
0
def test_track():
    # test data home None
    track_default = beatles.Track('0111')
    assert track_default._data_home == os.path.join(DEFAULT_DATA_HOME, 'Beatles')

    data_home = 'tests/resources/mir_datasets/Beatles'

    with pytest.raises(ValueError):
        beatles.Track('asdf', data_home=data_home)

    track = beatles.Track('0111', data_home=data_home)
    assert track.track_id == '0111'
    assert track._data_home == data_home
    assert track._track_paths == {
        'audio': [
            'audio/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.wav',
            '1b57c2f78ae0f19eed1ae7fbf747e12d',
        ],
        'beat': [
            'annotations/beat/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.txt',
            'f698ad2d802bf62fe10f59ea8b4af9f6',
        ],
        'chords': [
            'annotations/chordlab/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab',
            '24f12726a510c0321aa06cac95f27915',
        ],
        'keys': [
            'annotations/keylab/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab',
            'ca194503b783ed20521a1429411f3094',
        ],
        'sections': [
            'annotations/seglab/The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab',
            '509125d527dae09cdee832fc0a6e0580',
        ],
    }
    assert (
        track.audio_path
        == 'tests/resources/mir_datasets/Beatles/'
        + 'audio/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.wav'
    )
    assert track.title == '11_-_Do_You_Want_To_Know_A_Secret'
    assert type(track.beats) == utils.BeatData
    assert type(track.chords) == utils.ChordData
    assert type(track.key) == utils.KeyData
    assert type(track.sections) == utils.SectionData

    audio, sr = track.audio
    assert sr == 44100
    assert audio.shape == (44100 * 2,)

    repr_string = (
        "Beatles Track(track_id=0111, "
        + "audio_path=tests/resources/mir_datasets/Beatles/audio/"
        + "01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.wav, "
        + "title=11_-_Do_You_Want_To_Know_A_Secret, "
        + "beats=BeatData('beat_times, 'beat_positions'), "
        + "chords=ChordData('start_times', 'end_times', 'chords'), "
        + "key=KeyData('start_times', 'end_times', 'keys'), "
        + "sections=SectionData('start_times', 'end_times', 'sections'))"
    )
    assert track.__repr__() == repr_string

    track = beatles.Track('10212')
    assert track.beats == None
    assert track.key == None