Esempio n. 1
0
def test_jams():

    data = dict(time=[0.0, 1.0],
                duration=[0.5, 0.5],
                value=['one', 'two'],
                confidence=[0.9, 0.9])

    real_ann = jams.AnnotationArray(
        annotations=[jams.Annotation('tag_open', data=data)])
    meta = dict(title='Test track',
                artist='Test artist',
                release='Test release',
                duration=31.3)
    real_fm = jams.FileMetadata(**meta)

    real_sandbox = jams.Sandbox(description='none')

    def __test(annotations, file_metadata, sandbox):
        jam = jams.JAMS(annotations=annotations,
                        file_metadata=file_metadata,
                        sandbox=sandbox)

        if file_metadata is not None:
            eq_(dict(file_metadata), dict(jam.file_metadata))

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

        if annotations is not None:
            eq_(annotations, jam.annotations)

    for ann in [None, real_ann]:
        for fm in [None, real_fm]:
            for sandbox in [None, real_sandbox]:
                yield __test, ann, fm, sandbox
Esempio n. 2
0
def fill_global_metadata(jam, metadata, dur):
    """Fills the global metada into the JAMS jam."""
    meta = jams.FileMetadata(title=metadata[7],
                             artist=metadata[8],
                             duration=dur,
                             jams_version=jams.version.version)
    jam.file_metadata = meta
Esempio n. 3
0
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)
Esempio n. 4
0
def test_filemetadata():

    meta = dict(title='Test track',
                artist='Test artist',
                release='Test release',
                duration=31.3)
    fm = jams.FileMetadata(**meta)
    dict_fm = dict(fm)

    for k in meta:
        assert meta[k] == dict_fm[k]
Esempio n. 5
0
def test_filemetadata_validation(strict):

    # This should fail validation because null duration is not allowed
    fm = jams.FileMetadata(title='Test track',
                           artist='Test artist',
                           release='Test release',
                           duration=None)

    clean_warning_registry()

    with warnings.catch_warnings(record=True) as out:
        fm.validate(strict=strict)

        assert len(out) > 0
        assert out[0].category is UserWarning
        assert 'failed validating' in str(out[0].message).lower()
Esempio n. 6
0
def smc_file_metadata(infile):
    '''Construct a metadata object from an SMC wav file'''

    match = re.match('.*(?P<index>SMC_\d+).wav$', infile)

    if not match:
        raise RuntimeError('Could not index filename {:s}'.format(infile))

    # Get the duration of the track
    y, sr = librosa.load(infile, sr=None)
    duration = librosa.get_duration(y=y, sr=sr)

    # Format duration as time
    metadata = jams.FileMetadata(title=match.group('index'), duration=duration)

    return metadata
Esempio n. 7
0
def test_jams_add_conflict(on_conflict):
    fn = 'tests/fixtures/valid.jams'

    # The original jam
    jam = jams.load(fn)
    jam_orig = jams.load(fn)

    # The copy
    jam2 = jams.load(fn)

    jam2.file_metadata = jams.FileMetadata()

    jam.add(jam2, on_conflict=on_conflict)

    if on_conflict == 'overwrite':
        assert jam.file_metadata == jam2.file_metadata
    elif on_conflict == 'ignore':
        assert jam.file_metadata == jam_orig.file_metadata
Esempio n. 8
0
    def __test_conflict(on_conflict):
        fn = 'fixtures/valid.jams'

        # The original jam
        jam = jams.load(fn)
        jam_orig = jams.load(fn)

        # The copy
        jam2 = jams.load(fn)

        jam2.file_metadata = jams.FileMetadata()

        jam.add(jam2, on_conflict=on_conflict)

        if on_conflict == 'overwrite':
            eq_(jam.file_metadata, jam2.file_metadata)
        elif on_conflict == 'ignore':
            eq_(jam.file_metadata, jam_orig.file_metadata)
Esempio n. 9
0
def process_track(input_dir, output_dir, metadata, tags, compress):

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

    artist, _ = metadata['track'].split('-', 1)

    artist = ARTIST_MAP.get(artist, artist)

    title = metadata['track'].replace('{:s}-'.format(artist), '')

    artist = artist.replace('_', ' ')
    title = title.replace('_', ' ')

    file_meta = jams.FileMetadata(title=title,
                                  artist=artist,
                                  duration=duration)

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

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

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

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

    save_jam(output_dir, jam, metadata.name, compress)
def pred_to_jam(beats, pred):
    time = 0.0
    label = ud.labels[pred[0]]
    observations = []
    
    n = len(pred)
    for i in range(0,n):
        if ud.labels[pred[i]] == label: continue
        else:
            new_time = beats[i]
            new_label = ud.labels[pred[i]]

            observations.append(jams.Observation(time, new_time-time, label, None))

            time = new_time
            label = new_label
    observations.append(jams.Observation(time, beats[-1]-time, ud.labels[pred[-1]], None))

    annotation = jams.Annotation("segment_open"
                                , observations
                                , jd.get_annotation_metadata()
                                , jd.get_sandbox())
    jam = jams.JAMS([annotation], jams.FileMetadata(duration=beats[-1]))
    return jam
Esempio n. 11
0
def file_metadata():
    return jams.FileMetadata(title='Test track', artist='Test artist',
                             release='Test release', duration=31.3)