# Path: msaf/input_output.py
# class FileStruct:
#     def __init__(self, audio_file):
#         """Creates the entire file structure given the audio file."""
#         self.ds_path = os.path.dirname(os.path.dirname(audio_file))
#         self.audio_file = audio_file
#         self.est_file = self._get_dataset_file(ds_config.estimations_dir,
#                                                ds_config.estimations_ext)
#         self.features_file = self._get_dataset_file(ds_config.features_dir,
#                                                     ds_config.features_ext)
#         self.ref_file = self._get_dataset_file(ds_config.references_dir,
#                                                ds_config.references_ext)
# 
#     def _get_dataset_file(self, dir, ext):
#         """Gets the desired dataset file."""
#         audio_file_ext = "." + self.audio_file.split(".")[-1]
#         base_file = os.path.basename(self.audio_file).replace(
#             audio_file_ext, ext)
#         return os.path.join(self.ds_path, dir, base_file)
# 
#     def __repr__(self):
#         """Prints the file structure."""
#         return "FileStruct(\n\tds_path=%s,\n\taudio_file=%s,\n\test_file=%s," \
#             "\n\tfeatures_file=%s,\n\tref_file=%s\n)" % (
#                 self.ds_path, self.audio_file, self.est_file,
#                 self.features_file, self.ref_file)


import jams
import librosa
import numpy as np
import os
import shutil
import msaf
from nose.tools import raises
from msaf.input_output import FileStruct
# nosetests


# Msaf imports

# Global vars
audio_file = os.path.join("fixtures", "chirp.mp3")
sr = msaf.config.sample_rate


def test_read_hier_references():
    one_jams = os.path.join("..", "datasets", "Sargon", "references",
                            "01-Sargon-Mindless.jams")
    three_jams = os.path.join("..", "datasets", "SALAMI", "references",
                              "SALAMI_200.jams")

    audio, fs = librosa.load(audio_file, sr=sr)
    y_harmonic, y_percussive = librosa.effects.hpss(audio)

    # One level file
    hier_bounds, hier_labels, hier_levels = \
        msaf.io.read_hier_references(one_jams)
    assert len(hier_bounds) == len(hier_labels) and \
        len(hier_labels) == len(hier_levels)
    assert len(hier_levels) == 1

    # Three level file
    hier_bounds, hier_labels, hier_levels = \
        msaf.io.read_hier_references(three_jams)
    assert len(hier_bounds) == len(hier_labels) and \

# Path: msaf/input_output.py
# class FileStruct:
#     def __init__(self, audio_file):
#         """Creates the entire file structure given the audio file."""
#         self.ds_path = os.path.dirname(os.path.dirname(audio_file))
#         self.audio_file = audio_file
#         self.est_file = self._get_dataset_file(ds_config.estimations_dir,
#                                                ds_config.estimations_ext)
#         self.features_file = self._get_dataset_file(ds_config.features_dir,
#                                                     ds_config.features_ext)
#         self.ref_file = self._get_dataset_file(ds_config.references_dir,
#                                                ds_config.references_ext)
# 
#     def _get_dataset_file(self, dir, ext):
#         """Gets the desired dataset file."""
#         audio_file_ext = "." + self.audio_file.split(".")[-1]
#         base_file = os.path.basename(self.audio_file).replace(
#             audio_file_ext, ext)
#         return os.path.join(self.ds_path, dir, base_file)
# 
#     def __repr__(self):
#         """Prints the file structure."""
#         return "FileStruct(\n\tds_path=%s,\n\taudio_file=%s,\n\test_file=%s," \
#             "\n\tfeatures_file=%s,\n\tref_file=%s\n)" % (
#                 self.ds_path, self.audio_file, self.est_file,
#                 self.features_file, self.ref_file)


# Path: tests/test_input_output.py
import jams
import librosa
import numpy as np
import os
import shutil
import msaf
from nose.tools import raises
from msaf.input_output import FileStruct

# nosetests


# Msaf imports

# Global vars
audio_file = os.path.join("fixtures", "chirp.mp3")
sr = msaf.config.sample_rate


def test_read_hier_references():
    one_jams = os.path.join("..", "datasets", "Sargon", "references",
                            "01-Sargon-Mindless.jams")
    three_jams = os.path.join("..", "datasets", "SALAMI", "references",
                              "SALAMI_200.jams")

    audio, fs = librosa.load(audio_file, sr=sr)
    y_harmonic, y_percussive = librosa.effects.hpss(audio)

    # One level file
    hier_bounds, hier_labels, hier_levels = \
        msaf.io.read_hier_references(one_jams)
    assert len(hier_bounds) == len(hier_labels) and \
        len(hier_labels) == len(hier_levels)
    assert len(hier_levels) == 1

    # Three level file
    hier_bounds, hier_labels, hier_levels = \
        msaf.io.read_hier_references(three_jams)
    assert len(hier_bounds) == len(hier_labels) and \

        len(hier_labels) == len(hier_levels)