How to use the mirdata.utils.KeyData function in mirdata

To help you get started, we’ve selected a few mirdata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mir-dataset-loaders / mirdata / tests / test_guitarset.py View on Github external
+ 'audio_mono-mic/03_BN3-119-G_solo_mic.wav',
        'audio_mix_path': 'tests/resources/mir_datasets/GuitarSet/'
            + 'audio_mono-pickup_mix/03_BN3-119-G_solo_mix.wav',
        'jams_path': 'tests/resources/mir_datasets/GuitarSet/'
            + 'annotation/03_BN3-119-G_solo.jams',
        'player_id': '03',
        'tempo': 119,
        'mode': 'solo',
        'style': 'Bossa Nova',
    }

    expected_property_types = {
        'beats': utils.BeatData,
        'leadsheet_chords': utils.ChordData,
        'inferred_chords': utils.ChordData,
        'key_mode': utils.KeyData,
        'pitch_contours': dict,
        'notes': dict,
    }

    run_track_tests(track, expected_attributes, expected_property_types)

    assert type(track.pitch_contours['E']) is utils.F0Data
    assert type(track.notes['E']) is utils.NoteData
github mir-dataset-loaders / mirdata / tests / test_jams_utils.py View on Github external
def test_keys():
    key_data_1 = [
        (utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), None)
    ]
    key_data_2 = [
        (utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), 'keys_1')
    ]
    key_data_3 = [
        (utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), 'keys_1'),
        (utils.KeyData(np.array([0.0]), np.array([50.0]), np.array(['B'])), 'keys_2'),
    ]
    key_data_4 = (
        utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])),
        'keys_1',
    )
    key_data_5 = [
        [utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), 'keys_1'],
        (utils.KeyData(np.array([0.0]), np.array([50.0]), np.array(['B'])), 'keys_2'),
    ]
    key_data_6 = [(None, None)]
    key_data_7 = [
        (
            utils.EventData(
                np.array([0.2, 0.3]),
                np.array([0.3, 0.4]),
                np.array(['event A', 'event B']),
github mir-dataset-loaders / mirdata / tests / test_jams_utils.py View on Github external
def test_keys():
    key_data_1 = [
        (utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), None)
    ]
    key_data_2 = [
        (utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), 'keys_1')
    ]
    key_data_3 = [
        (utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), 'keys_1'),
        (utils.KeyData(np.array([0.0]), np.array([50.0]), np.array(['B'])), 'keys_2'),
    ]
    key_data_4 = (
        utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])),
        'keys_1',
    )
    key_data_5 = [
        [utils.KeyData(np.array([0.0]), np.array([100.0]), np.array(['A'])), 'keys_1'],
        (utils.KeyData(np.array([0.0]), np.array([50.0]), np.array(['B'])), 'keys_2'),
    ]
    key_data_6 = [(None, None)]
    key_data_7 = [
        (
            utils.EventData(
                np.array([0.2, 0.3]),
                np.array([0.3, 0.4]),
                np.array(['event A', 'event B']),
            ),
            None,
        )
github mir-dataset-loaders / mirdata / tests / test_beatles.py View on Github external
def test_load_key():
    key_path = (
        'tests/resources/mir_datasets/Beatles/annotations/keylab/'
        + 'The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab'
    )
    key_data = beatles.load_key(key_path)

    assert type(key_data) == utils.KeyData
    assert type(key_data.start_times) == np.ndarray

    assert np.array_equal(key_data.start_times, np.array([0.000]))
    assert np.array_equal(key_data.end_times, np.array([119.333]))
    assert np.array_equal(key_data.keys, np.array(['E']))

    assert beatles.load_key(None) is None
github mir-dataset-loaders / mirdata / mirdata / beatles.py View on Github external
(utils.KeyData): loaded key data

    """
    if keys_path is None or not os.path.exists(keys_path):
        return None

    start_times, end_times, keys = [], [], []
    with open(keys_path, 'r') as fhandle:
        reader = csv.reader(fhandle, delimiter='\t')
        for line in reader:
            if line[2] == 'Key':
                start_times.append(float(line[0]))
                end_times.append(float(line[1]))
                keys.append(line[3])

    key_data = utils.KeyData(np.array(start_times), np.array(end_times), np.array(keys))

    return key_data
github mir-dataset-loaders / mirdata / mirdata / guitarset.py View on Github external
def load_key_mode(jams_path):
    jam = jams.load(jams_path)
    anno = jam.search(namespace='key_mode')[0]
    intervals, values = anno.to_interval_values()
    return utils.KeyData(intervals[:, 0], intervals[:, 1], values)
github mir-dataset-loaders / mirdata / mirdata / jams_utils.py View on Github external
Convert keys annotations into jams format.

    Parameters
    ----------
    keys: tuple
        A tuple in the format (KeyData, str), where str describes the annotation
        and KeyData is the keys mirdata annotation format.

    Returns
    -------
    jannot_key: JAM key_mode annotation object.
    '''
    jannot_key = jams.Annotation(namespace='key_mode')
    jannot_key.annotation_metadata = jams.AnnotationMetadata(data_source='mirdata')
    if keys[0] is not None:
        if type(keys[0]) != utils.KeyData:
            raise TypeError('Type should be KeyData.')
        for beg, end, key in zip(keys[0].start_times, keys[0].end_times, keys[0].keys):
            jannot_key.append(time=beg, duration=end - beg, value=key)
    if keys[1] is not None:
        jannot_key.sandbox = jams.Sandbox(name=keys[1])
    return jannot_key