Skip to content

Commit

Permalink
Merge pull request jdasam#13 from luciaicull/refactoring_yj
Browse files Browse the repository at this point in the history
update load_composer_name and dataset objects
  • Loading branch information
jdasam authored Jan 30, 2020
2 parents 1b4cf4c + e2175d4 commit 55b3a82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class DataSet:
def __init__(self, path, data_structure='folder'):
self.path = path
self.dataset_name = copy.copy(path).split('/')[-1]
self.pieces = []
self.performances = []
self.performs_by_tag = {}
Expand All @@ -54,7 +55,7 @@ def _load_all_scores(self):
# musicxml_list = sorted(path.glob('**.xml'))
for xml in musicxml_list:
try:
piece = PieceData(xml, data_structure=self.data_structure)
piece = PieceData(xml, data_structure=self.data_structure, dataset_name=self.dataset_name)
self.pieces.append(piece)
except Exception as ex:
print('Error type :', ex)
Expand Down Expand Up @@ -193,8 +194,8 @@ def _divide_by_tag(self, list_of_tag):

# score data class
class PieceData:
def __init__(self, xml_path, data_structure='folder', composer=None):
self.meta = PieceMeta(xml_path, data_structure, composer=composer)
def __init__(self, xml_path, data_structure='folder', dataset_name='chopin_cleaned', composer=None):
self.meta = PieceMeta(xml_path, data_structure, dataset_name=dataset_name, composer=composer)
self.xml_obj = None
self.xml_notes = None
self.num_notes = 0
Expand All @@ -215,7 +216,6 @@ def __init__(self, xml_path, data_structure='folder', composer=None):
self.meta._load_composer_name()

def _load_score_xml(self):
print(self.meta.xml_path)
self.xml_obj = MusicXMLDocument(str(self.meta.xml_path))
self._get_direction_encoded_notes()
self.notes_graph = score_graph.make_edge(self.xml_notes)
Expand Down Expand Up @@ -271,9 +271,10 @@ def __str__(self):

# score meta data class
class PieceMeta:
def __init__(self, xml_path, data_structure='folder', composer=None):
def __init__(self, xml_path, data_structure='folder', dataset_name='chopin_cleaned', composer=None):
self.xml_path = xml_path
self.folder_path = os.path.dirname(xml_path)
self.dataset_name = dataset_name
self.composer = composer
self.data_structure = data_structure
self.pedal_elongate = False
Expand Down Expand Up @@ -339,14 +340,14 @@ def align_score_and_perf_with_nakamura(self, midi_file_path):
os.chdir(current_dir)

def _load_composer_name(self):

print(self.folder_path)
if self.data_structure == 'folder':
# self.folder_path = 'pyScoreParser/chopin_cleaned/{composer_name}/...'
path_split = copy.copy(self.folder_path).split('/')
if path_split[0] == 'chopin_cleaned':
if path_split[0] == self.dataset_name:
composer_name = path_split[1]
else:
dataset_folder_name_index = path_split.index('chopin_cleaned')
dataset_folder_name_index = path_split.index(self.dataset_name)
composer_name = path_split[dataset_folder_name_index+1]
else:
# self.folder_path = '.../emotionDataset/{data_name.mid}'
Expand Down
2 changes: 2 additions & 0 deletions test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

import argparse
from .data_class import DataSet



parser = argparse.ArgumentParser()
parser.add_argument('dataset_path', type=str)
args = parser.parse_args()
Expand Down

0 comments on commit 55b3a82

Please sign in to comment.