def load_chords(chords_path): """Load rwc chord data from a file Args: chords_path (str): path to chord annotation file Returns: ChordData: chord data """ 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 annotations.ChordData(np.array([begs, ends]).T, chords)
def load_chords(chords_path): """Load Beatles format chord data from a file Args: chords_path (str): path to chord annotation file Returns: ChordData: loaded chord data """ if chords_path is None: return None if not os.path.exists(chords_path): raise IOError("chords_path {} does not exist".format(chords_path)) 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 = annotations.ChordData( np.array([start_times, end_times]).T, chords) return chord_data
def test_chord_data(): intervals = np.array([[1.0, 2.0], [1.5, 3.0], [2.0, 3.0]]) labels = ["E:m", "A", "G:7"] confidence = np.array([0.1, 0.4, 0.2]) chord_data = annotations.ChordData(intervals, labels, confidence) assert np.allclose(chord_data.intervals, intervals) assert chord_data.labels == labels assert np.allclose(chord_data.confidence, confidence)
def load_chords(fhandle: TextIO) -> annotations.ChordData: """Load Queen format chord data from a file Args: fhandle (str or file-like): path or file-like object pointing to a chord file Returns: (ChordData): loaded chord data """ start_times, end_times, chords = [], [], [] reader = csv.reader(fhandle, delimiter="\t") for line in reader: start_times.append(float(line[0])) end_times.append(float(line[1])) chords.append(line[2]) return annotations.ChordData(np.array([start_times, end_times]).T, chords)
def load_chords(fhandle: TextIO) -> annotations.ChordData: """Load Beatles format chord data from a file Args: fhandle (str or file-like): path or file-like object pointing to a chord annotation file Returns: ChordData: loaded chord data """ start_times, end_times, chords = [], [], [] dialect = csv.Sniffer().sniff(fhandle.read(1024)) fhandle.seek(0) reader = csv.reader(fhandle, dialect) for line in reader: start_times.append(float(line[0])) end_times.append(float(line[1])) chords.append(line[2]) return annotations.ChordData(np.array([start_times, end_times]).T, chords)
def load_chords(fhandle: TextIO) -> annotations.ChordData: """Load rwc chord data from a file Args: fhandle (str or file-like): File-like object or path to chord annotation file Returns: ChordData: chord data """ begs = [] # timestamps of chord beginnings ends = [] # timestamps of chord endings chords = [] # chord labels 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 annotations.ChordData(np.array([begs, ends]).T, chords)
def load_chords(jams_path, leadsheet_version=True): """Load a guitarset chord annotation. 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 """ if not os.path.exists(jams_path): raise IOError("jams_path {} does not exist".format(jams_path)) 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 annotations.ChordData(intervals, values)
def load_chords(fhandle: TextIO): """Load chords from a Salami LAB file. Args: fhandle (str or file-like): path to audio file Returns: ChordData: chord data """ start_times = [] end_times = [] chords = [] reader = csv.reader(fhandle, delimiter="\t") for l in reader: if len(l): start_times.append(float(l[0])) end_times.append(float(l[1])) chords.append(l[2]) chord_data = annotations.ChordData( np.array([start_times, end_times]).T, chords) return chord_data
def test_chords(): chord_data_1 = [ ( annotations.ChordData( np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T, ["A", "A", "E"], ), None, ) ] chord_data_2 = [ ( annotations.ChordData( np.array([[0.0, 0.8, 1.0], [0.5, 1.0, 1.5]]).T, ["A", "B", "C"], ), "chords_2", ) ] chord_data_3 = [ ( annotations.ChordData( np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T, ["A", "A", "E"], ), "chords_1", ), ( annotations.ChordData( np.array([[0.0, 0.7, 1.0], [0.7, 1.0, 1.5]]).T, ["A", "B", "C"], ), "chords_2", ), ] chord_data_4 = ( annotations.ChordData( np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T, ["A", "A", "E"] ), None, ) chord_data_5 = [ [ annotations.ChordData( np.array([[0.0, 0.5, 1.0], [0.5, 1.0, 1.5]]).T, ["A", "A", "E"], ), None, ], ( annotations.ChordData( np.array([[0.0, 0.8, 1.0], [0.5, 1.0, 1.5]]).T, ["A", "B", "C"], ), "chords_2", ), ] chord_data_6 = [(None, None)] chord_data_7 = [ ( annotations.EventData( np.array([[0.2, 0.3], [0.3, 0.4]]).T, ["event A", "event B"], ), None, ) ] jam_1 = jams_utils.jams_converter(chord_data=chord_data_1) jam_2 = jams_utils.jams_converter(chord_data=chord_data_2) jam_3 = jams_utils.jams_converter(chord_data=chord_data_3) jam_6 = jams_utils.jams_converter(chord_data=chord_data_6) time, duration, value, confidence = get_jam_data(jam_1, "chord", 0) assert time == [0.0, 0.5, 1.0] assert duration == [0.5, 0.5, 0.5] assert value == ["A", "A", "E"] assert confidence == [None, None, None] assert jam_2.annotations[0]["sandbox"]["name"] == "chords_2" time, duration, value, confidence = get_jam_data(jam_3, "chord", 0) assert time == [0.0, 0.5, 1.0] assert duration == [0.5, 0.5, 0.5] assert value == ["A", "A", "E"] assert confidence == [None, None, None] time, duration, value, confidence = get_jam_data(jam_3, "chord", 1) assert time == [0.0, 0.7, 1.0] assert duration == [0.7, 0.3, 0.5] assert value == ["A", "B", "C"] assert confidence == [None, None, None] time, duration, value, confidence = get_jam_data(jam_6, "chord", 0) assert time == [] assert duration == [] assert value == [] assert confidence == [] assert type(jam_1) == jams.JAMS with pytest.raises(TypeError): jams_utils.jams_converter(chord_data=chord_data_4) with pytest.raises(TypeError): jams_utils.jams_converter(chord_data=chord_data_5) with pytest.raises(TypeError): jams_utils.jams_converter(chord_data=chord_data_7)