Exemple #1
0
def events_to_jams(events):
    """
    Convert events annotations into jams format.

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

    Returns
    -------
    jannot_events: JAM tag_open annotation object.
    """
    jannot_events = jams.Annotation(namespace="tag_open")
    jannot_events.annotation_metadata = jams.AnnotationMetadata(
        data_source="mirdata")
    if events[0] is not None:
        if type(events[0]) != utils.EventData:
            raise TypeError("Type should be EventData.")
        for beg, end, label in zip(events[0].start_times, events[0].end_times,
                                   events[0].event):
            jannot_events.append(time=beg,
                                 duration=end - beg,
                                 value=str(label))
    if events[1] is not None:
        jannot_events.sandbox = jams.Sandbox(name=events[1])
    return jannot_events
Exemple #2
0
def lyrics_to_jams(lyric_data, description=None):
    """Convert lyric annotations into jams format.

    Args:
        lyric_data (annotations.LyricData): lyric annotation object
        description (str): annotation descriptoin

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_lyric = jams.Annotation(namespace="lyrics")
    jannot_lyric.annotation_metadata = jams.AnnotationMetadata(
        data_source="mirdata")

    if lyric_data is not None:
        if not isinstance(lyric_data, annotations.LyricData):
            raise TypeError("Type should be LyricData.")
        for beg, end, lyric in zip(lyric_data.intervals[:, 0],
                                   lyric_data.intervals[:,
                                                        1], lyric_data.lyrics):
            jannot_lyric.append(time=beg, duration=end - beg, value=lyric)
    if description is not None:
        jannot_lyric.sandbox = jams.Sandbox(name=description)
    return jannot_lyric
Exemple #3
0
def f0s_to_jams(f0s):
    """
    Convert f0 annotations into jams format.

    Parameters
    ----------
    f0s: tuple
        A tuple in the format (F0Data, str), where str describes the annotation
        and F0Data is the f0 mirdata annotation format.

    Returns
    -------
    jannot_f0: JAM pitch_contour annotation object.
    """
    jannot_f0 = jams.Annotation(namespace="pitch_contour")
    jannot_f0.annotation_metadata = jams.AnnotationMetadata(
        data_source="mirdata")
    if f0s[0] is not None:
        if not isinstance(f0s[0], utils.F0Data):
            raise TypeError("Type should be F0Data.")
        for t, f, c in zip(f0s[0].times, f0s[0].frequencies,
                           f0s[0].confidence):
            jannot_f0.append(
                time=t,
                duration=0.0,
                value={
                    "index": 0,
                    "frequency": f,
                    "voiced": f > 0
                },
                confidence=c,
            )
    if f0s[1] is not None:
        jannot_f0.sandbox = jams.Sandbox(name=f0s[1])
    return jannot_f0
Exemple #4
0
def events_to_jams(event_data, description=None):
    """Convert events annotations into jams format.

    Args:
        event_data (annotations.EventData): event data object
        description (str): annotation description

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_events = jams.Annotation(namespace="tag_open")
    jannot_events.annotation_metadata = jams.AnnotationMetadata(
        data_source="mirdata")

    if event_data is not None:
        if not isinstance(event_data, annotations.EventData):
            raise TypeError("Type should be EventData.")
        for beg, end, label in zip(event_data.intervals[:, 0],
                                   event_data.intervals[:,
                                                        1], event_data.events):
            jannot_events.append(time=beg, duration=end - beg, value=label)
    if description is not None:
        jannot_events.sandbox = jams.Sandbox(name=description)
    return jannot_events
Exemple #5
0
def events_to_jams(events, annotator=None, description=None):
    """Convert events annotations into jams format.

    Args:
        events (annotations.Events): events data object
        annotator (str): annotator id
        description (str): annotation description

    Returns:
        jams.Annotation: jams annotation object.

    """

    jannot_events = jams.Annotation(namespace="segment_open")
    jannot_events.annotation_metadata = jams.AnnotationMetadata(
        data_source="soundata",
        annotator={"id": annotator} if annotator is not None else None,
    )

    for inter, label, conf in zip(events.intervals, events.labels,
                                  events.confidence):
        jannot_events.append(time=inter[0],
                             duration=inter[1] - inter[0],
                             value=label,
                             confidence=conf)
    if description is not None:
        jannot_events.sandbox = jams.Sandbox(name=description)
    return jannot_events
def process_track(input_dir, output_dir, metadata, tags, compress):

    # Construct track metadata
    duration = get_track_duration(
        os.path.join(input_dir, 'audio', metadata['filename']))

    file_meta = jams.FileMetadata(title=metadata['title'],
                                  artist=metadata['artist'],
                                  duration=duration,
                                  identifiers=jams.Sandbox(id=metadata.name))

    # Get the tag annotation
    amd = jams.AnnotationMetadata(curator=jams.Curator(**__curator__),
                                  corpus=__corpus__)

    ann = jams.Annotation('tag_cal10k', annotation_metadata=amd)

    for tag in tags:
        ann.append(time=0, duration=duration, value=tag)

    jam = jams.JAMS(file_metadata=file_meta)
    jam.annotations.append(ann)
    jam.sandbox.content_path = metadata['filename']

    save_jam(output_dir, jam, metadata.name, compress)
Exemple #7
0
def chords_to_jams(chords):
    '''
    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
Exemple #8
0
def beats_to_jams(beats):
    '''
    Convert beats annotations into jams format.

    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
Exemple #9
0
def keys_to_jams(keys):
    '''
    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
Exemple #10
0
def sections_to_jams(section_data, description=None):
    """Convert section annotations into jams format.

    Args:
        section_data (annotations.SectionData): section data object
        description (str): annotation description

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_seg = jams.Annotation(namespace="segment_open")
    jannot_seg.annotation_metadata = jams.AnnotationMetadata(
        data_source="mirdata")

    if section_data is not None:
        if not isinstance(section_data, annotations.SectionData):
            raise TypeError("Type should be SectionData.")
        for inter, seg in zip(section_data.intervals, section_data.labels):
            jannot_seg.append(time=inter[0],
                              duration=inter[1] - inter[0],
                              value=seg)
    if description is not None:
        jannot_seg.sandbox = jams.Sandbox(name=description)
    return jannot_seg
def create_jam_file(jams_dir, key, corpus, estimate):
    """
    Create a jam file for the given key, corpus, and estimate.

    :param jams_dir: dir
    :param key: file id
    :param corpus: corpus (e.g. Ballroom)
    :param estimate: tempo estimate
    """
    makedirs(jams_dir, exist_ok=True)
    if estimate < 0:
        logging.warning('Attempting to store tempo estimate for {} that is less than 0: {}'.format(key, estimate))
        estimate = 0
    tempo = jams.Annotation(namespace='tempo')
    tempo.append(time=0.0,
                 duration='nan',
                 value=estimate,
                 confidence=1.0)
    tempo.annotation_metadata = jams.AnnotationMetadata(
        corpus=corpus,
        version='1.0',
        data_source='')
    jam = jams.JAMS()
    jam.annotations.append(tempo)
    jam.file_metadata.duration = 5000  # bogus value to please JAMS
    jam.save(join(jams_dir, '{}.jams'.format(key)))
Exemple #12
0
def tags_to_jams(tags,
                 annotator=None,
                 duration=0,
                 namespace="tag_open",
                 description=None):
    """Convert tags annotations into jams format.

    Args:
        tags (annotations.Tags): tags annotation object
        annotator (str): annotator id
        namespace (str): the jams-compatible tag namespace
        description (str): annotation description

    Returns:
        jams.Annotation: jams annotation object.

    """
    ann = jams.Annotation(namespace=namespace)
    ann.annotation_metadata = jams.AnnotationMetadata(
        data_source="soundata",
        annotator={"id": annotator} if annotator is not None else None,
    )
    for t, c in zip(tags.labels, tags.confidence):
        ann.append(time=0.0, duration=duration, value=t, confidence=c)
    if description is not None:
        ann.sandbox = jams.Sandbox(name=description)
    return ann
Exemple #13
0
def lyrics_to_jams(lyrics):
    '''
    Convert lyrics annotations into jams format.

    Parameters
    ----------
    lyrics: tuple
        A tuple in the format (LyricData, str), where str describes the annotation
        and LyricData is the lyric mirdata annotation format.

    Returns
    -------
    jannot_lyric: JAM lyric annotation object.
    '''
    jannot_lyric = jams.Annotation(namespace='lyrics')
    jannot_lyric.annotation_metadata = jams.AnnotationMetadata(
        data_source='mirdata')
    if lyrics[0] is not None:
        if type(lyrics[0]) != utils.LyricData:
            raise TypeError('Type should be LyricData.')
        for beg, end, lyric in zip(lyrics[0].start_times, lyrics[0].end_times,
                                   lyrics[0].lyrics):
            jannot_lyric.append(time=beg, duration=end - beg, value=lyric)
    if lyrics[1] is not None:
        jannot_lyric.sandbox = jams.Sandbox(name=lyrics[1])
    return jannot_lyric
Exemple #14
0
def f0s_to_jams(f0s):
    '''
    Convert f0 annotations into jams format.

    Parameters
    ----------
    f0s: tuple
        A tuple in the format (F0Data, str), where str describes the annotation
        and F0Data is the f0 mirdata annotation format.

    Returns
    -------
    jannot_f0: JAM pitch_contour annotation object.
    '''
    jannot_f0 = jams.Annotation(namespace='pitch_contour')
    jannot_f0.annotation_metadata = jams.AnnotationMetadata(
        data_source='mirdata')
    if f0s[0] is not None:
        if type(f0s[0]) != utils.F0Data:
            raise TypeError('Type should be F0Data.')
        for t, f, c in zip(f0s[0].times, f0s[0].frequencies,
                           f0s[0].confidence):
            jannot_f0.append(time=t, duration=0.0, value=f, confidence=c)
    if f0s[1] is not None:
        jannot_f0.sandbox = jams.Sandbox(name=f0s[1])
    return jannot_f0
Exemple #15
0
def test_annotation():
    def __test(namespace, data, amd, sandbox):
        ann = jams.Annotation(namespace,
                              data=data,
                              annotation_metadata=amd,
                              sandbox=sandbox)

        eq_(namespace, ann.namespace)

        if amd is not None:
            eq_(dict(amd), dict(ann.annotation_metadata))

        if sandbox is not None:
            eq_(dict(sandbox), dict(ann.sandbox))

        if data is not None:
            assert ann.data.equals(jams.JamsFrame.from_dict(data))

    real_sandbox = jams.Sandbox(description='none')
    real_amd = jams.AnnotationMetadata(corpus='test collection')
    real_data = dict(time=[0.0, 1.0],
                     duration=[0.5, 0.5],
                     value=['one', 'two'],
                     confidence=[0.9, 0.9])

    namespace = 'tag_open'

    for data in [None, real_data]:
        for amd in [None, real_amd]:
            for sandbox in [None, real_sandbox]:
                yield __test, namespace, data, amd, sandbox
def f0s_to_jams(f0_data, description=None):
    """Convert f0 annotations into jams format.

    Args:
        f0_data (annotations.F0Data): f0 annotation object
        description (str): annotation descriptoin

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_f0 = jams.Annotation(namespace="pitch_contour")
    jannot_f0.annotation_metadata = jams.AnnotationMetadata(data_source="mirdata")

    if f0_data is not None:
        if not isinstance(f0_data, annotations.F0Data):
            raise TypeError("Type should be F0Data.")
        for t, f, c in zip(f0_data.times, f0_data.frequencies, f0_data.confidence):
            jannot_f0.append(
                time=t,
                duration=0.0,
                value={"index": 0, "frequency": f, "voiced": f > 0},
                confidence=c,
            )
    if description is not None:
        jannot_f0.sandbox = jams.Sandbox(name=description)
    return jannot_f0
def save_jams(jamsfile, notes, track_duration, orig_filename):

    # Construct a new JAMS object and annotation records
    jam = jams.JAMS()

    # Store the track duration
    jam.file_metadata.duration = track_duration
    jam.file_metadata.title = orig_filename

    midi_an = jams.Annotation(namespace='pitch_midi', duration=track_duration)
    midi_an.annotation_metadata = \
        jams.AnnotationMetadata(
            data_source='audio_to_midi_melodia.py v%s' % __init__.__version__,
            annotation_tools='audio_to_midi_melodia.py (https://github.com/'
                             'justinsalamon/audio_to_midi_melodia)')

    # Add midi notes to the annotation record.
    for n in notes:
        midi_an.append(time=n[0], duration=n[1], value=n[2], confidence=0)

    # Store the new annotation in the jam
    jam.annotations.append(midi_an)

    # Save to disk
    jam.save(jamsfile)
Exemple #18
0
def notes_to_jams(notes):
    '''
    Convert notes annotations into jams format using note_to_midi from librosa.

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

    Returns
    -------
    jannot_notes: JAM note_midi annotation object.
    '''
    jannot_note = jams.Annotation(namespace='note_hz')
    jannot_note.annotation_metadata = jams.AnnotationMetadata(
        data_source='mirdata')
    if notes[0] is not None:
        if type(notes[0]) != utils.NoteData:
            raise TypeError('Type should be NoteData.')
        for beg, end, n in zip(notes[0].intervals[:, 0],
                               notes[0].intervals[:, 1], notes[0].notes):
            jannot_note.append(time=beg, duration=end - beg, value=n)
    if notes[1] is not None:
        jannot_note.sandbox = jams.Sandbox(name=notes[1])
    return jannot_note
Exemple #19
0
def sections_to_jams(sections):
    '''
    Convert sections annotations into jams format.

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

    Returns
    -------
    jannot_seg: JAM segment_open annotation object.
    '''
    jannot_seg = jams.Annotation(namespace='segment_open')
    jannot_seg.annotation_metadata = jams.AnnotationMetadata(
        data_source='mirdata')
    if sections[0] is not None:
        if type(sections[0]) != utils.SectionData:
            raise TypeError('Type should be SectionData.')
        for inter, seg in zip(sections[0].intervals, sections[0].labels):
            jannot_seg.append(time=inter[0],
                              duration=inter[1] - inter[0],
                              value=seg)
    if sections[1] is not None:
        jannot_seg.sandbox = jams.Sandbox(name=sections[1])
    return jannot_seg
def process(in_dir, out_dir):
    """Converts the original Isophonic files into the JAMS format, and saves
    them in the out_dir folder."""
    all_jams = dict()
    output_paths = dict()
    all_labs = jams.util.find_with_extension(in_dir, 'lab', 5)
    all_labs += jams.util.find_with_extension(in_dir, 'txt', 4)

    for lab_file in all_labs:
        title = jams.util.filebase(lab_file)
        if not title in all_jams:
            all_jams[title] = jams.JAMS()
            parts = lab_file.replace(in_dir, '').strip('/').split('/')
            fill_file_metadata(all_jams[title], artist=parts[1], title=title)
            output_paths[title] = os.path.join(
                out_dir, *parts[1:]).replace(".lab", ".jams")
            logging.info("%s -> %s" % (title, output_paths[title]))

        jam = all_jams[title]
        if ISO_ATTRS['beat'] in lab_file:
            try:
                tmp_jam, annot = jams.util.import_lab(NS_DICT['beat'], lab_file,
                                                      jam=jam)
            except TypeError:
                tmp_jam, annot = jams.util.import_lab(NS_DICT['beat'], lab_file,
                                                      jam=jam, sep="\t+")
            fix_beats_values(annot)
        elif ISO_ATTRS['chord'] in lab_file:
            tmp_jam, annot = jams.util.import_lab(NS_DICT['chord'], lab_file,
                                                  jam=jam)
            fix_chord_labels(jam.annotations[-1])
            fix_ranges(jam.annotations[-1])
            jam.file_metadata.duration = get_duration_from_annot(annot)
        elif ISO_ATTRS['key'] in lab_file:
            tmp_jam, annot = jams.util.import_lab(NS_DICT['key'], lab_file,
                                                  jam=jam)
            fix_key_labels(jam.annotations[-1])
            fix_ranges(jam.annotations[-1])
            fix_silence(jam.annotations[-1])
        elif ISO_ATTRS['segment'] in lab_file:
            tmp_jam, annot = jams.util.import_lab(NS_DICT['segment'], lab_file,
                                                  jam=jam)
            fix_ranges(jam.annotations[-1])
            jam.file_metadata.duration = get_duration_from_annot(annot)

        # Add Metadata
        curator = jams.Curator(name="Matthias Mauch",
                               email="*****@*****.**")
        ann_meta = jams.AnnotationMetadata(curator=curator,
                                           version=1.0,
                                           corpus="Isophonics",
                                           annotator=None)
        jam.annotations[-1].annotation_metadata = ann_meta

    logging.info("Saving and validating JAMS...")
    for title in all_jams:
        out_file = output_paths[title]
        jams.util.smkdirs(os.path.split(out_file)[0])
        all_jams[title].save(out_file)
Exemple #21
0
def test_annotation_metadata(ann_meta_dummy, curator, annotator):

    md = jams.AnnotationMetadata(curator=curator, annotator=annotator,
                                 **ann_meta_dummy)

    if curator is not None:
        assert dict(md.curator) == dict(curator)

    if annotator is not None:
        assert dict(md.annotator) == dict(annotator)

    real_data = dict(md)
    real_data.pop('curator')
    real_data.pop('annotator')
    assert real_data == ann_meta_dummy
Exemple #22
0
    def __test(data, curator, annotator):

        md = jams.AnnotationMetadata(curator=curator,
                                     annotator=annotator,
                                     **data)

        if curator is not None:
            eq_(dict(md.curator), dict(curator))

        if annotator is not None:
            eq_(dict(md.annotator), dict(annotator))

        real_data = dict(md)
        real_data.pop('curator')
        real_data.pop('annotator')
        eq_(real_data, data)
Exemple #23
0
def convert_am(am2, corpus="", curator_name="", curator_email=""):
    """Converts the annotation metadata 2 and returns it."""
    am = jams.AnnotationMetadata()
    am.data_source = am2["origin"]
    am.annotation_rules = am2["annotation_rules"]
    am.validation = am2["validation_and_reliability"]
    am.annotation_tools = am2["annotation_tools"]
    am.annotator.name = am2["annotator"]["name"]
    am.version = am2["version"]
    if am2["corpus"] == "":
        am.corpus = corpus
    else:
        am.corpus = am2["corpus"]
    am.curator.name = curator_name
    am.curator.email = curator_email
    return am
Exemple #24
0
    def serializeTrack(path, track: Track, features=[{"namespace": "beat", "data_source": "Madmom", 'feature': "beats"}]):
        """
        Serialize a track in jams format
        """
        jam = jams.JAMS()
        jam.file_metadata.duration = track.getDuration()
        for feature in features:
            annotation = jams.Annotation(namespace=feature["namespace"])
            annotation.annotation_metadata = jams.AnnotationMetadata(data_source=feature["data_source"])

            for t in track.getFeature(feature["feature"]):
                annotation.append(time=t, duration=0.0)

            jam.annotations.append(annotation)

        jam.save(path)
def get_annotation_metadata():
    # metadata = {
    #     "curator": {
    #       "name": "",
    #       "email": ""
    #     },
    #     "annotator": {},
    #     "version": "",
    #     "corpus": "",
    #     "annotation_tools": "",
    #     "annotation_rules": "",
    #     "validation": "",
    #     "data_source": "MSAF"
    # }
    metadata = jams.AnnotationMetadata(data_source='MSAF')
    return metadata
def tempos_to_jams(tempo_data, description=None):
    """Convert tempo annotations into jams format.

    Args:
        tempo_data (annotations.TempoData): tempo data object
        description (str): annotation description

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_tempo = jams.Annotation(namespace="tempo")
    jannot_tempo.annotation_metadata = jams.AnnotationMetadata(data_source="mirdata")
    if tempo_data is not None:
        if not isinstance(tempo_data, float) and not isinstance(tempo_data, int):
            raise TypeError("Type should be float or int.")
        jannot_tempo.append(time=0, duration=0, confidence=1, value=tempo_data)
    if description is not None:
        jannot_tempo.sandbox = jams.Sandbox(name=description)
    return jannot_tempo
Exemple #27
0
def make_jam(freq_dict,sr,track_duration):
    """
    this function creates a jam according to a dictionary that specifies 
    each frequency's presence 

    dict: keys are frequencies
          values are list of tuples (start_time, duration) of that frequency
    """
    jam = jams.JAMS()

    # Store the track duration
    jam.file_metadata.duration = track_duration

    pitch_co = jams.Annotation(namespace='pitch_contour')
    note_h = jams.Annotation(namespace='note_hz')
    note_m = jams.Annotation(namespace='note_midi')
    pitch_cl = jams.Annotation(namespace='pitch_class')
    pitch_h = jams.Annotation(namespace='pitch_hz')
    pitch_m = jams.Annotation(namespace='pitch_midi')
    
    pitch_co.annotation_metadata = jams.AnnotationMetadata(data_source='synth')
    note_h.annotation_metadata = jams.AnnotationMetadata(data_source='synth')
    note_m.annotation_metadata = jams.AnnotationMetadata(data_source='synth')
    pitch_cl.annotation_metadata = jams.AnnotationMetadata(data_source='synth')
    pitch_h.annotation_metadata = jams.AnnotationMetadata(data_source='synth')
    pitch_m.annotation_metadata = jams.AnnotationMetadata(data_source='synth')


    #assign frequencies to each start_time
    freqs = freq_dict.keys()
    for f in freqs:
        time_dur = freq_dict[f] #list of tuples (start_time,duration)
        for t, dur in time_dur:
            pitch_co.append(time=t, duration=dur, value={"index":0,"frequency":f,"voiced":True})
            note_h.append(time=t, duration=dur,value=f)
            note_m.append(time=t, duration=dur, value=librosa.hz_to_midi(f))
            pclass = librosa.hz_to_note(f)
            pitch_cl.append(time=t, duration=dur,value={"tonic":pclass[:-1],"pitch":int(pclass[-1])})
            pitch_h.append(time=t, duration=dur,value=f)
            pitch_m.append(time=t, duration=dur, value=librosa.hz_to_midi(f))
    # Store the new annotation in the jam
    jam.annotations.append(pitch_co)
    jam.annotations.append(note_h)
    jam.annotations.append(note_m)
    jam.annotations.append(pitch_cl)
    jam.annotations.append(pitch_h)
    jam.annotations.append(pitch_m)

    return jam
def tag_to_jams(tag_data, namespace="tag_open", description=None):
    """Convert lyric annotations into jams format.

    Args:
        lyric_data (annotations.LyricData): lyric annotation object
        namespace (str): the jams-compatible tag namespace
        description (str): annotation descriptoin

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_tag = jams.Annotation(namespace=namespace)
    jannot_tag.annotation_metadata = jams.AnnotationMetadata(data_source="mirdata")
    if tag_data is not None:
        if not isinstance(tag_data, str):
            raise TypeError("Type should be str.")
        jannot_tag.append(time=0.0, duration=0.0, value=tag_data)
    if description is not None:
        jannot_tag.sandbox = jams.Sandbox(name=description)
    return jannot_tag
Exemple #29
0
def tag_open_to_jams(tags):
    """
    Convert tag-open annotations into jams format.
    Parameters
    ----------
    tags: tuple
        A tuple in the format (str, str), where the first str is the open tag
        and the second describes the annotation.
    Returns
    -------
    jannot_tag_open: JAM tag_open annotation object.
    """
    jannot_tag_open = jams.Annotation(namespace="tag_open")
    jannot_tag_open.annotation_metadata = jams.AnnotationMetadata(
        data_source="mirdata")
    if tags[0] is not None:
        if not isinstance(tags[0], str):
            raise TypeError("Type should be str.")
        jannot_tag_open.append(time=0.0, duration=0.0, value=tags[0])
    if tags[1] is not None:
        jannot_tag_open.sandbox = jams.Sandbox(name=tags[1])
    return jannot_tag_open
def beats_to_jams(beat_data, description=None):
    """Convert beat annotations into jams format.

    Args:
        beat_data (annotations.BeatData): beat data object
        description (str): annotation description

    Returns:
        jams.Annotation: jams annotation object.

    """
    jannot_beat = jams.Annotation(namespace="beat")
    jannot_beat.annotation_metadata = jams.AnnotationMetadata(data_source="mirdata")

    if beat_data is not None:
        if not isinstance(beat_data, annotations.BeatData):
            raise TypeError("Type should be BeatData.")
        for t, p in zip(beat_data.times, beat_data.positions):
            jannot_beat.append(time=t, duration=0.0, value=p)
    if description is not None:
        jannot_beat.sandbox = jams.Sandbox(name=description)
    return jannot_beat