Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a base Track class, remove all reprs #205

Merged
merged 4 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ from __future__ import print_function

# -- import whatever you need here

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand Down Expand Up @@ -170,7 +171,7 @@ DATA = utils.LargeData('example_index.json', _load_metadata)
# DATA = utils.LargeData('example_index.json') ## use this if your dataset has no metadata


class Track(object):
class Track(track.Track):
"""Example track class
# -- YOU CAN AUTOMATICALLY GENERATE THIS DOCSTRING BY CALLING THE SCRIPT:
# -- `scripts/print_track_docstring.py my_dataset`
Expand Down Expand Up @@ -212,14 +213,6 @@ class Track(object):
else:
self.some_metadata = None

# -- this lets users run `print(Track)` and get actual information
def __repr__(self):
repr_string = "Example Track(track_id={}, audio_path={}, " + \
"some_metadata{}, "
"annotation=AnnotationData('start_times', 'end_times', 'annotation'), " + \
return repr_string.format(
self.track_id, self.audio_path, self.some_metadata)

# -- `annotation` will behave like an attribute, but it will only be loaded
# -- and saved when someone accesses it. Useful when loading slightly
# -- bigger files or for bigger datasets. By default, we make any time
Expand Down
6 changes: 6 additions & 0 deletions docs/source/mirdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ mirdata.tinysol
Utilities
----------

mirdata.track
^^^^^^^^^^^^^

.. automodule:: mirdata.track
:members:

mirdata.utils
^^^^^^^^^^^^^

Expand Down
13 changes: 2 additions & 11 deletions mirdata/beatles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import numpy as np

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand All @@ -26,7 +27,7 @@
DATA = utils.LargeData('beatles_index.json')


class Track(object):
class Track(track.Track):
"""Beatles track class

Args:
Expand Down Expand Up @@ -70,16 +71,6 @@ def __init__(self, track_id, data_home=None):

self.title = os.path.basename(self._track_paths['sections'][0]).split('.')[0]

def __repr__(self):
repr_string = (
"Beatles Track(track_id={}, audio_path={}, title={}, "
+ "beats=BeatData('beat_times, 'beat_positions'), "
+ "chords=ChordData('intervals', 'labels'), "
+ "key=KeyData('start_times', 'end_times', 'keys'), "
+ "sections=SectionData('intervals', 'labels'))"
)
return repr_string.format(self.track_id, self.audio_path, self.title)

@utils.cached_property
def beats(self):
"""BeatData: human-labeled beat annotation"""
Expand Down
25 changes: 2 additions & 23 deletions mirdata/dali.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
)
raise

import mirdata.track as track
import mirdata.utils as utils

DATASET_DIR = 'DALI'
Expand All @@ -55,7 +56,7 @@ def _load_metadata(data_home):
DATA = utils.LargeData('dali_index.json', _load_metadata)


class Track(object):
class Track(track.Track):
"""DALI melody Track class

Args:
Expand Down Expand Up @@ -133,28 +134,6 @@ def __init__(self, track_id, data_home=None):
self.language = None
self.audio_path = None

def __repr__(self):
repr_string = (
"DALI Track(track_id={}, audio_path={}, "
+ "audio_url={}, audio_working={}, ground_truth={}, artist={}, title={},"
+ "dataset_version={}, scores_ncc={}, scores_manual={}, album={}, release_date={}, language={})"
)
return repr_string.format(
self.track_id,
self.audio_path,
self.audio_url,
self.url_working,
self.ground_truth,
self.artist,
self.title,
self.dataset_version,
round(self.scores_ncc, 4),
self.scores_manual,
self.album,
self.release_date,
self.language,
)

@utils.cached_property
def notes(self):
"""NoteData: note-aligned lyrics"""
Expand Down
8 changes: 2 additions & 6 deletions mirdata/gtzan_genre.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import librosa

from mirdata import download_utils
import mirdata.track as track
from mirdata import utils


Expand All @@ -34,7 +35,7 @@
DATA = utils.LargeData("gtzan_genre_index.json")


class Track(object):
class Track(track.Track):
"""gtzan_genre Track class

Args:
Expand Down Expand Up @@ -71,11 +72,6 @@ def audio(self):
"""(np.ndarray, float): audio signal, sample rate"""
return load_audio(self.audio_path, sample_rate=22050)

def __repr__(self):
return "GTZAN-Genre Track(track_id='{track_id}', genre='{genre}')".format(
track_id=self.track_id, genre=self.genre
)

def to_jams(self):
"""(Not Implemented) Jams: the track's data in jams format"""
raise NotImplementedError
Expand Down
17 changes: 2 additions & 15 deletions mirdata/guitarset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import jams
import logging

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils

Expand Down Expand Up @@ -99,7 +100,7 @@
DATA = utils.LargeData('guitarset_index.json')


class Track(object):
class Track(track.Track):
"""guitarset Track class

Args:
Expand Down Expand Up @@ -157,20 +158,6 @@ def __init__(self, track_id, data_home=None):
self.tempo = float(tempo)
self.style = _STYLE_DICT[style[:-1]]

def __repr__(self):
repr_string = (
'GuitarSet Track('
+ 'track_id={}, jams_path={},\n'.format(self.track_id, self.jams_path)
+ 'tempo={}, mode={}, style={},\n'.format(self.tempo, self.mode, self.style)
+ "beats=BeatData('beat_times', 'beat_positions'),\n"
+ "leadsheet_chords=ChordData('start_times', 'end_times', 'chords'),\n"
+ "inferred_chords=ChordData('start_times', 'end_times', 'chords'),\n"
+ "key_mode=KeyData('start_times', 'end_times', 'keys'),\n"
+ "pitch_contours=dict(F0Data('times', 'frequencies', 'confidence')),\n"
+ "notes=dict(NoteData('intervals', 'notes', 'confidence')))"
)
return repr_string

@utils.cached_property
def beats(self):
"""BeatData: the track's beat positions"""
Expand Down
14 changes: 2 additions & 12 deletions mirdata/ikala.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import logging
import numpy as np

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand Down Expand Up @@ -63,7 +64,7 @@ def _load_metadata(data_home):
DATA = utils.LargeData('ikala_index.json', _load_metadata)


class Track(object):
class Track(track.Track):
"""ikala Track class

Args:
Expand Down Expand Up @@ -107,17 +108,6 @@ def __init__(self, track_id, data_home=None):
else:
self.singer_id = None

def __repr__(self):
repr_string = (
"iKala Track(track_id={}, audio_path={}, song_id={}, "
+ "section={}, singer_id={}, "
+ "f0=F0Data('times', 'frequencies', 'confidence'), "
+ "lyrics=LyricData('start_times', 'end_times', 'lyrics', 'pronunciations'))"
)
return repr_string.format(
self.track_id, self.audio_path, self.song_id, self.section, self.singer_id
)

@utils.cached_property
def f0(self):
"""F0Data: The human-annotated singing voice pitch"""
Expand Down
12 changes: 2 additions & 10 deletions mirdata/medley_solos_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import logging
import os

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand Down Expand Up @@ -80,7 +81,7 @@ def _load_metadata(data_home):
DATA = utils.LargeData("medley_solos_db_index.json", _load_metadata)


class Track(object):
class Track(track.Track):
"""medley_solos_db Track class

Args:
Expand Down Expand Up @@ -130,15 +131,6 @@ def __init__(self, track_id, data_home=None):
self.song_id = self._track_metadata["song_id"]
self.subset = self._track_metadata["subset"]

def __repr__(self):
repr_string = (
"Medley-solos-DB Track(track_id={}, audio_path={}, "
+ "instrument={}, song_id={}, subset={})"
)
return repr_string.format(
self.track_id, self.audio_path, self.instrument, self.song_id, self.subset
)

@property
def audio(self):
"""(np.ndarray, float): audio signal, sample rate"""
Expand Down
23 changes: 2 additions & 21 deletions mirdata/medleydb_melody.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import numpy as np
import os

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand All @@ -45,7 +46,7 @@ def _load_metadata(data_home):
DATA = utils.LargeData('medleydb_melody_index.json', _load_metadata)


class Track(object):
class Track(track.Track):
"""medleydb_melody Track class

Args:
Expand Down Expand Up @@ -112,26 +113,6 @@ def __init__(self, track_id, data_home=None):
self.is_instrumental = self._track_metadata['is_instrumental']
self.n_sources = self._track_metadata['n_sources']

def __repr__(self):
repr_string = (
"MedleyDb-Melody Track(track_id={}, audio_path={}, "
+ "artist={}, title={}, genre={}, is_excerpt={}, "
+ "is_instrumental={}, n_sources={}, "
+ "melody1=F0Data('times', 'frequencies', confidence'), "
+ "melody2=F0Data('times', 'frequencies', confidence'), "
+ "melody3=MultipitchData('times', 'frequencies', confidence'))"
)
return repr_string.format(
self.track_id,
self.audio_path,
self.artist,
self.title,
self.genre,
self.is_excerpt,
self.is_instrumental,
self.n_sources,
)

@utils.cached_property
def melody1(self):
"""F0Data: The pitch of the single most predominant source (often the voice)"""
Expand Down
18 changes: 2 additions & 16 deletions mirdata/medleydb_pitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import numpy as np
import os

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand All @@ -45,7 +46,7 @@ def _load_metadata(data_home):
DATA = utils.LargeData('medleydb_pitch_index.json', _load_metadata)


class Track(object):
class Track(track.Track):
"""medleydb_pitch Track class

Args:
Expand Down Expand Up @@ -96,21 +97,6 @@ def __init__(self, track_id, data_home=None):
self.title = self._track_metadata['title']
self.genre = self._track_metadata['genre']

def __repr__(self):
repr_string = (
"MedleyDb-Pitch Track(track_id={}, audio_path={}, "
+ "artist={}, title={}, genre={}, instrument={}, "
+ "pitch=PitchData('times', 'pitches', 'confidence'))"
)
return repr_string.format(
self.track_id,
self.audio_path,
self.artist,
self.title,
self.genre,
self.instrument,
)

@utils.cached_property
def pitch(self):
"""F0Data: The human-annotated pitch"""
Expand Down
29 changes: 2 additions & 27 deletions mirdata/orchset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import shutil

import mirdata.track as track
import mirdata.utils as utils
import mirdata.download_utils as download_utils
import mirdata.jams_utils as jams_utils
Expand Down Expand Up @@ -98,7 +99,7 @@ def _load_metadata(data_home):
DATA = utils.LargeData('orchset_index.json', _load_metadata)


class Track(object):
class Track(track.Track):
"""orchset Track class

Args:
Expand Down Expand Up @@ -177,32 +178,6 @@ def __init__(self, track_id, data_home=None):
self.only_winds = self._track_metadata['only_winds']
self.only_brass = self._track_metadata['only_brass']

def __repr__(self):
repr_string = (
"Orchset Track(track_id={}, audio_path_stereo={}, "
+ "audio_path_mono={}, composer={}, work={}, excerpt={}, "
+ "predominant_melodic_instruments={}, alternating_melody={}, "
+ "contains_winds={}, contains_strings={}, contains_brass={}, "
+ "only_strings={}, only_winds={}, only_brass={}, "
+ "melody=F0Data('times', 'frequencies', 'confidence'))"
)
return repr_string.format(
self.track_id,
self.audio_path_stereo,
self.audio_path_mono,
self.composer,
self.work,
self.excerpt,
self.predominant_melodic_instruments,
self.alternating_melody,
self.contains_winds,
self.contains_strings,
self.contains_brass,
self.only_strings,
self.only_winds,
self.only_brass,
)

@utils.cached_property
def melody(self):
"""F0Data: melody annotation"""
Expand Down
Loading