How to use the mirdata.utils.BeatData 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_hex_path': 'tests/resources/mir_datasets/GuitarSet/'
            + 'audio_hex-pickup_original/03_BN3-119-G_solo_hex.wav',
        'audio_mic_path': 'tests/resources/mir_datasets/GuitarSet/'
            + '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_beats():
    beat_data_1 = [(utils.BeatData(np.array([0.2, 0.3]), np.array([1, 2])), None)]
    beat_data_2 = [(utils.BeatData(np.array([0.5, 0.7]), np.array([2, 3])), 'beats_2')]
    beat_data_3 = [
        (utils.BeatData(np.array([0.0, 0.3]), np.array([1, 2])), 'beats_1'),
        (utils.BeatData(np.array([0.5, 0.13]), np.array([4, 3])), 'beats_2'),
    ]
    beat_data_4 = (utils.BeatData(np.array([0.0, 0.3]), np.array([1, 2])), 'beats_1')
    beat_data_5 = [
        (utils.BeatData(np.array([0.0, 0.3]), np.array([1, 2])), 'beats_1'),
        [utils.BeatData(np.array([0.5, 0.13]), np.array([4, 3])), 'beats_2'],
    ]
    beat_data_6 = [(None, None)]
    beat_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
'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
    assert audio.shape == (44100 * 2,)

    track = beatles.Track('10212')
    assert track.beats is None
    assert track.key is None
github mir-dataset-loaders / mirdata / tests / test_rwc_classical.py View on Github external
def test_load_beats():
    beats_path = (
        'tests/resources/mir_datasets/RWC-Classical/'
        + 'annotations/AIST.RWC-MDB-C-2001.BEAT/RM-C003.BEAT.TXT'
    )
    beat_data = rwc_classical.load_beats(beats_path)

    # check types
    assert type(beat_data) is utils.BeatData
    assert type(beat_data.beat_times) is np.ndarray
    assert type(beat_data.beat_positions) is np.ndarray

    # check values
    assert np.array_equal(
        beat_data.beat_times, np.array([1.65, 2.58, 2.95, 3.33, 3.71, 4.09, 5.18, 6.28])
    )
    assert np.array_equal(beat_data.beat_positions, np.array([2, 1, 2, 1, 2, 1, 2, 1]))

    # load a file which doesn't exist
    beats_data_none = rwc_classical.load_beats('fake/path')
    assert beats_data_none is None
github mir-dataset-loaders / mirdata / mirdata / groove_midi.py View on Github external
def beats(self):
        """BeatData: machine-generated beat annotation"""
        beat_times = self.midi.get_beats()
        beat_range = np.arange(0, len(beat_times))
        meter = self.midi.time_signature_changes[0]
        beat_positions = 1 + np.mod(beat_range, meter.numerator)
        return utils.BeatData(beat_times, beat_positions)
github mir-dataset-loaders / mirdata / mirdata / beatles.py View on Github external
return None

    beat_times, beat_positions = [], []
    with open(beats_path, 'r') as fhandle:
        dialect = csv.Sniffer().sniff(fhandle.read(1024))
        fhandle.seek(0)
        reader = csv.reader(fhandle, dialect)
        for line in reader:
            beat_times.append(float(line[0]))
            beat_positions.append(line[-1])

    beat_positions = _fix_newpoint(np.array(beat_positions))
    # After fixing New Point labels convert positions to int
    beat_positions = [int(b) for b in beat_positions]

    beat_data = utils.BeatData(np.array(beat_times), np.array(beat_positions))

    return beat_data
github mir-dataset-loaders / mirdata / mirdata / guitarset.py View on Github external
def load_beats(jams_path):
    jam = jams.load(jams_path)
    anno = jam.search(namespace='beat_position')[0]
    times, values = anno.to_event_values()
    positions = [int(v['position']) for v in values]
    return utils.BeatData(times, positions)
github mir-dataset-loaders / mirdata / mirdata / jams_utils.py View on Github external
Parameters
    ----------
    beats: tuple
        A tuple in the format (BeatData, str), where str describes the annotation
        and BeatData is the beats mirdata annotation format.

    Returns
    -------
    jannot_beat: JAM beat annotation object.

    '''
    jannot_beat = jams.Annotation(namespace='beat')
    jannot_beat.annotation_metadata = jams.AnnotationMetadata(data_source='mirdata')
    if beats[0] is not None:
        if type(beats[0]) != utils.BeatData:
            raise TypeError('Type should be BeatData.')
        for t, p in zip(beats[0].beat_times, beats[0].beat_positions):
            jannot_beat.append(time=t, duration=0.0, value=p)
    if beats[1] is not None:
        jannot_beat.sandbox = jams.Sandbox(name=beats[1])
    return jannot_beat