How to use the mirdata.utils.ChordData 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_jams_utils.py View on Github external
utils.ChordData(
                np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T,
                np.array(['A', 'A', 'E']),
            ),
            'chords_1',
        ),
        (
            utils.ChordData(
                np.array([[0.0, 0.7, 1.0], [0.7, 1.0, 1.5]]).T,
                np.array(['A', 'B', 'C']),
            ),
            'chords_2',
        ),
    ]
    chord_data_4 = (
        utils.ChordData(
            np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T, np.array(['A', 'A', 'E'])
        ),
        None,
    )
    chord_data_5 = [
        [
            utils.ChordData(
                np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T,
                np.array(['A', 'A', 'E']),
            ),
            None,
        ],
        (
            utils.ChordData(
                np.array([[0.0, 0.8, 1.0], [0.5, 1.0, 1.5]]).T,
                np.array(['A', 'B', 'C']),
github mir-dataset-loaders / mirdata / tests / test_jams_utils.py View on Github external
def test_chords():
    chord_data_1 = [
        (
            utils.ChordData(
                np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T,
                np.array(['A', 'A', 'E']),
            ),
            None,
        )
    ]
    chord_data_2 = [
        (
            utils.ChordData(
                np.array([[0.0, 0.8, 1.0], [0.5, 1.0, 1.5]]).T,
                np.array(['A', 'B', 'C']),
            ),
            'chords_2',
        )
    ]
    chord_data_3 = [
github mir-dataset-loaders / mirdata / tests / test_rwc_popular.py View on Github external
'piece_number': 'No. 1',
        'suffix': 'M01',
        'track_number': 'Tr. 01',
        'title': 'Eien no replica',
        'artist': 'Kazuo Nishi',
        'singer_information': 'Male',
        'duration': 209,
        'tempo': '135',
        'instruments': 'Gt',
        'drum_information': 'Drum sequences',
    }

    expected_property_types = {
        'beats': utils.BeatData,
        'sections': utils.SectionData,
        'chords': utils.ChordData,
        'vocal_instrument_activity': utils.EventData,
    }

    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,)
github mir-dataset-loaders / mirdata / tests / test_beatles.py View on Github external
def test_load_chords():
    chords_path = (
        'tests/resources/mir_datasets/Beatles/annotations/chordlab/'
        + 'The Beatles/01_-_Please_Please_Me/11_-_Do_You_Want_To_Know_A_Secret.lab'
    )
    chord_data = beatles.load_chords(chords_path)

    assert type(chord_data) == utils.ChordData
    assert type(chord_data.intervals) == np.ndarray
    assert type(chord_data.labels) == list

    assert np.array_equal(
        chord_data.intervals[:, 0], np.array([0.000000, 4.586464, 6.989730])
    )
    assert np.array_equal(
        chord_data.intervals[:, 1], np.array([0.497838, 6.989730, 9.985104])
    )
    assert np.array_equal(chord_data.labels, np.array(['N', 'E:min', 'G']))

    assert beatles.load_chords(None) is None
github mir-dataset-loaders / mirdata / mirdata / rwc_popular.py View on Github external
if not os.path.exists(chords_path):
        raise IOError("chords_path {} does not exist".format(chords_path))

    begs = []  # timestamps of chord beginnings
    ends = []  # timestamps of chord endings
    chords = []  # chord labels

    if os.path.exists(chords_path):
        with open(chords_path, 'r') as fhandle:
            reader = csv.reader(fhandle, delimiter='\t')
            for line in reader:
                begs.append(float(line[0]))
                ends.append(float(line[1]))
                chords.append(line[2])

    return utils.ChordData(np.array([begs, ends]).T, chords)
github mir-dataset-loaders / mirdata / mirdata / beatles.py View on Github external
"""
    if chords_path is None or not os.path.exists(chords_path):
        return None

    start_times, end_times, chords = [], [], []
    with open(chords_path, 'r') as f:
        dialect = csv.Sniffer().sniff(f.read(1024))
        f.seek(0)
        reader = csv.reader(f, dialect)
        for line in reader:
            start_times.append(float(line[0]))
            end_times.append(float(line[1]))
            chords.append(line[2])

    chord_data = utils.ChordData(np.array([start_times, end_times]).T, chords)

    return chord_data
github mir-dataset-loaders / mirdata / mirdata / jams_utils.py View on Github external
Convert chords annotations into jams format.

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

    Returns
    -------
    jannot_chord: JAM chord annotation object.
    '''
    jannot_chord = jams.Annotation(namespace='chord')
    jannot_chord.annotation_metadata = jams.AnnotationMetadata(data_source='mirdata')
    if chords[0] is not None:
        if type(chords[0]) != utils.ChordData:
            raise TypeError('Type should be ChordData.')
        for beg, end, ch in zip(
            chords[0].intervals[:, 0], chords[0].intervals[:, 1], chords[0].labels
        ):
            jannot_chord.append(time=beg, duration=end - beg, value=ch)
    if chords[1] is not None:
        jannot_chord.sandbox = jams.Sandbox(name=chords[1])
    return jannot_chord
github mir-dataset-loaders / mirdata / mirdata / guitarset.py View on Github external
Args:
        jams_path (str): Path of the jams annotation file
        leadsheet_version (Bool)
            Whether or not to load the leadsheet version of the chord annotation
            If False, load the infered version.

    Returns:
        (ChordData): Chord data
    """
    jam = jams.load(jams_path)
    if leadsheet_version:
        anno = jam.search(namespace='chord')[0]
    else:
        anno = jam.search(namespace='chord')[1]
    intervals, values = anno.to_interval_values()
    return utils.ChordData(intervals, values)