def test_track():
    # test data home None
    track_default = rwc_classical.Track('RM-C003')
    assert track_default._data_home == os.path.join(DEFAULT_DATA_HOME, 'RWC-Classical')

    # test data_home where the test data lives
    data_home = 'tests/resources/mir_datasets/RWC-Classical'

    with pytest.raises(ValueError):
        rwc_classical.Track('asdfasdf', data_home=data_home)

    track = rwc_classical.Track('RM-C003', data_home=data_home)

    # test attributes are loaded as expected
    assert track.track_id == 'RM-C003'
    assert track._data_home == data_home
    assert track._track_paths == {
        'audio': ['audio/rwc-c-m01/3.wav', 'a2f1accd0ae6ba4364069b3370a57578'],
        'sections': [
            'annotations/AIST.RWC-MDB-C-2001.CHORUS/RM-C003.CHORUS.TXT',
            '9805083e55f2547559ebdfa5f97ccb0e',
        ],
        'beats': [
            'annotations/AIST.RWC-MDB-C-2001.BEAT/RM-C003.BEAT.TXT',
            '3deaf6102c54c04596182ba904375e19',
        ],
    }
    assert (
        track.audio_path
        == 'tests/resources/mir_datasets/RWC-Classical/' + 'audio/rwc-c-m01/3.wav'
    )
    assert track.piece_number == 'No. 3'
    assert track.suffix == 'M01'
    assert track.track_number == 'Tr. 03'
    assert track.title == 'Symphony no.5 in C minor, op.67. 1st mvmt.'
    assert track.composer == 'Beethoven, Ludwig van'
    assert track.artist == 'Tokyo City Philharmonic Orchestra'
    assert track.duration_sec == '7:15'
    assert track.category == 'Symphony'

    # test that cached properties don't fail and have the expected type
    assert type(track.sections) is utils.SectionData
    assert type(track.beats) is utils.BeatData

    # test audio loading functions
    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2,)

    repr_string = (
        "RWC-Classical Track(track_id=RM-C003, "
        + "audio_path=tests/resources/mir_datasets/RWC-Classical/audio/rwc-c-m01/3.wav, "
        + "piece_number=No. 3, suffix=M01, track_number=Tr. 03, "
        + "title=Symphony no.5 in C minor, op.67. 1st mvmt., composer=Beethoven, Ludwig van, "
        + "artist=Tokyo City Philharmonic Orchestra, duration_sec=7:15, category=Symphony"
        + "sections=SectionData('start_times', 'end_times', 'sections'), "
        + "beats=BeatData('beat_times', 'beat_positions'))"
    )
    assert track.__repr__() == repr_string
Exemple #2
0
def test_track():
    default_trackid = 'RM-C003'
    data_home = 'tests/resources/mir_datasets/RWC-Classical'
    track = rwc_classical.Track(default_trackid, data_home=data_home)

    expected_attributes = {
        'track_id': 'RM-C003',
        'audio_path': 'tests/resources/mir_datasets/RWC-Classical/' +
        'audio/rwc-c-m01/3.wav',
        'sections_path': 'tests/resources/mir_datasets/RWC-Classical/' +
        'annotations/AIST.RWC-MDB-C-2001.CHORUS/RM-C003.CHORUS.TXT',
        'beats_path': 'tests/resources/mir_datasets/RWC-Classical/' +
        'annotations/AIST.RWC-MDB-C-2001.BEAT/RM-C003.BEAT.TXT',
        'piece_number': 'No. 3',
        'suffix': 'M01',
        'track_number': 'Tr. 03',
        'title': 'Symphony no.5 in C minor, op.67. 1st mvmt.',
        'composer': 'Beethoven, Ludwig van',
        'artist': 'Tokyo City Philharmonic Orchestra',
        'duration': 435,
        'category': 'Symphony',
    }

    expected_property_types = {
        'beats': utils.BeatData,
        'sections': utils.SectionData
    }

    run_track_tests(track, expected_attributes, expected_property_types)

    # test audio loading functions
    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2, )
Exemple #3
0
def test_to_jams():

    data_home = 'tests/resources/mir_datasets/RWC-Classical'
    track = rwc_classical.Track('RM-C003', data_home=data_home)
    jam = track.to_jams()

    beats = jam.search(namespace='beat')[0]['data']
    assert [beat.time for beat in beats] == [
        1.65,
        2.58,
        2.95,
        3.33,
        3.71,
        4.09,
        5.18,
        6.28,
    ]
    assert [beat.duration
            for beat in beats] == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    assert [beat.value for beat in beats] == [2, 1, 2, 1, 2, 1, 2, 1]
    assert [beat.confidence for beat in beats] == [
        None,
        None,
        None,
        None,
        None,
        None,
        None,
        None,
    ]

    segments = jam.search(namespace='segment')[0]['data']
    assert [segment.time for segment in segments] == [0.29, 419.96]
    assert [segment.duration for segment in segments] == [45.85, 13.75]
    assert [segment.value for segment in segments] == ['chorus A', 'ending']
    assert [segment.confidence for segment in segments] == [None, None]

    assert jam['file_metadata'][
        'title'] == 'Symphony no.5 in C minor, op.67. 1st mvmt.'
    assert jam['file_metadata'][
        'artist'] == 'Tokyo City Philharmonic Orchestra'