class DataExtractor(DataMerger):
    """
    The class to extract the relevant information from a SymbTr score.

    The information include:
        * Obtain the makam, usul, form, name and composer of the given SymbTr
        score
        * Extract section boundaries from both the implicit and explicit
        section information given in the SymbTr scores
        * Extract annotated phrase boundaries in the SymbTr scores
        * Add user provided segment boundaries in the SymbTr scores
        * Analyse the melody and the lyrics of the sections, phrase
        annotations and user provided segmentations, and apply semiotic labels
        * Query relevant symbtr from MusicBrainz (if the MBID is supplied)

    Currently only the SymbTr-txt scores are supported. MusicXML and mu2
    support can be added, if demanded.
    """

    def __init__(self, lyrics_sim_thres=0.7, melody_sim_thres=0.7,
                 save_structure_sim=True, extract_all_labels=False,
                 crop_consec_bounds=True, print_warnings=True):
        """
        Class constructor

        Parameters
        ----------
        lyrics_sim_thres : float[0, 1], optional
            The similarity threshold for the lyrics of two sections/segments
            to be regarded as similar. (the default is 0.75)
        melody_sim_thres : float[0, 1], optional
            The similarity threshold for the melody of two sections/segments
            to be regarded as similar. (the default is 0.75)
        save_structure_sim : bool, optional
            True to add the melodic and lyrics similarity between each
            section and segment to the output, False otherwise
        extract_all_labels : bool, optional
            True to extract sections using all labels in written in the lyrics
            field regardless they are a section marking etc., False to only
            extract the lyrics. (the default is False)
        crop_consec_bounds : bool, optional
            True to remove the first of the two consecutive boundaries inside
            user given segmentation boundaries, False otherwise. (the
            default is True)
        print_warnings : bool, optional
            True to display warnings, False otherwise. Note that the errors
            and the inconsistencies in the scores will be always displayed
            (the default is True)
        """
        self._section_extractor = SectionExtractor(
            lyrics_sim_thres=lyrics_sim_thres,
            melody_sim_thres=melody_sim_thres,
            save_structure_sim=save_structure_sim,
            extract_all_labels=extract_all_labels,
            print_warnings=print_warnings)

        self._segment_extractor = SegmentExtractor(
            lyrics_sim_thres=lyrics_sim_thres,
            melody_sim_thres=melody_sim_thres,
            save_structure_sim=save_structure_sim,
            crop_consecutive_bounds=crop_consec_bounds)

    def extract(self, score_file, symbtr_name=None, mbid=None,
                segment_note_bound_idx=None):
        """
        Extracts the relevant (meta)data from the SymbTr score.

        Parameters
        ----------
        score_file : str
            The path of the SymbTr score
        symbtr_name : str, optional
            The name of the score in SymbTr naming convention
            (makam--form--usul--name--composer). Needed if the filename does
            not obey this convention. If not provided the method will
            attempt to recover the symbtr_name from the score_file input.
            (the default is None, which implies the name will be recovered
            from symbtr_file)
        mbid : str, optional
            The `MBID <https://musicbrainz.org/doc/MusicBrainz_Identifier>`_
            relevant to the SymbTr score. For the score of a composition the
            work mbid of the composition should be supplied. For the score
            of a transcribed recording the identifier should be a recording
            MBID. The MBID can either be given as the 36 character uuid
            (83291c8a-4ef1-4ffc-8b50-3fc03890f5a4) or as an html link
            (https://musicbrainz.org/work/83291c8a-4ef1-4ffc-8b50
            -3fc03890f5a4). In the first case the method will try to find
            whether the MBID belongs to a work or a recording automatically.
            (the default is None)
        segment_note_bound_idx : list[ind], optional
            Boundary indices obtained from user provided (automatic)
            segmentation.
            Currently this parameter is only supported for the SymbTr-txt
            scores. For automatic segmentation from the SymbTr-txt
            scores, you can use the `makam-symbolic-phrase-segmentation
            <https://github.com/MTG/makam-symbolic-phrase-segmentation>`_
            package. (the default is None)

        Returns
        ----------
        dict
            A dictionary storing all the relevant (meta)data
        bool
            True if the information bout the score is all valid/consistent,
            False otherwise

        Raises
        ------
        ValueError
            If either of melody_sim_thres or lyrics_sim_thres imputs is
            outside [0,1]
        """
        if symbtr_name is None:
            symbtr_name = os.path.splitext(os.path.basename(score_file))[0]

        # get the symbtr
        data, is_metadata_valid = MetadataExtractor.from_musicbrainz(
            symbtr_name, mbid=mbid)

        # get the extension to determine the SymbTr-score format
        extension = os.path.splitext(score_file)[1]

        # read the score
        score, is_score_content_valid = self._read_score(
            extension, score_file, symbtr_name)

        data['duration'] = {'value': sum(score['duration']) * 0.001,
                            'unit': 'second'}
        data['number_of_notes'] = len(score['duration'])

        data['sections'], is_section_data_valid = self._section_extractor. \
            from_txt_score(score, symbtr_name)

        anno_phrases = self._segment_extractor.extract_phrases(
            score, sections=data['sections'])
        segments = self._segment_extractor.extract_segments(
            score, segment_note_bound_idx, sections=data['sections'])

        data['rhythmic_structure'] = \
            RhythmicFeatureExtractor.extract_rhythmic_structure(score)

        data['segments'] = segments
        data['phrase_annotations'] = anno_phrases

        is_data_valid = all([is_metadata_valid, is_section_data_valid,
                             is_score_content_valid])

        return data, is_data_valid

    @staticmethod
    def _read_score(extension, score_file, symbtr_name):
        if extension == ".txt":
            score, is_score_content_valid = TxtReader.read(
                score_file, symbtr_name=symbtr_name)
        elif extension == ".xml":
            score, is_score_content_valid = MusicXMLReader.read(
                score_file, symbtr_name=symbtr_name)
        elif extension == ".mu2":
            score, is_score_content_valid = Mu2Reader.read(
                score_file, symbtr_name=symbtr_name)
        else:
            raise IOError("Unknown format")
        return score, is_score_content_valid

    # getter and setters
    @property
    def lyrics_sim_thres(self):
        self._assert_sim_threshold('lyrics')
        return self._segment_extractor.lyrics_sim_thres

    @lyrics_sim_thres.setter
    def lyrics_sim_thres(self, value):
        self._set_sim_thres(value, 'lyrics')

    @property
    def melody_sim_thres(self):
        self._assert_sim_threshold('melody')

        return self._segment_extractor.melody_sim_thres

    @melody_sim_thres.setter
    def melody_sim_thres(self, value):
        self._set_sim_thres(value, 'melody')

    def _assert_sim_threshold(self, name):
        p = name + '_sim_thres'
        segment_sim_thres = getattr(self._segment_extractor, p)
        section_sim_thres = getattr(self._section_extractor, p)
        assert segment_sim_thres == section_sim_thres, \
            'The {0:s} of the _segmentExtractor and _sectionExtractor ' \
            'should have the same value'.format(p)

    def _set_sim_thres(self, value, name):
        self._chk_sim_thres_val(value)
        setattr(self._segment_extractor, name + '_sim_thres', value)
        setattr(self._section_extractor, name + '_sim_thres', value)

    @staticmethod
    def _chk_sim_thres_val(value):
        if not 0 <= value <= 1:
            raise ValueError('The similarity threshold should be a float '
                             'between [0, 1]')

    @property
    def extract_all_labels(self):
        return self._section_extractor.extract_all_labels

    @extract_all_labels.setter
    def extract_all_labels(self, value):
        self._chk_bool(value)
        self._section_extractor.extract_all_labels = value

    @property
    def print_warnings(self):
        return self._section_extractor.print_warnings

    @print_warnings.setter
    def print_warnings(self, value):
        self._chk_bool(value)
        self._section_extractor.print_warnings = value

    @property
    def crop_consecutive_bounds(self):
        return self._segment_extractor.crop_consecutive_bounds

    @crop_consecutive_bounds.setter
    def crop_consecutive_bounds(self, value):
        self._chk_bool(value)
        self._segment_extractor.crop_consecutive_bounds = value

    @staticmethod
    def _chk_bool(value):
        if not isinstance(value, type(True)):
            raise ValueError('The property should be a boolean') class Mu2Reader(SymbTrReader):
    @classmethod
    def read(cls, score_file, symbtr_name=None):
        """
        Reader method for the SymbTr-mu2 scores. This method is not
        implemented yet.

        Parameters
        ----------
        score_file : str
            The path of the SymbTr score
        symbtr_name : str, optional
            The name of the score in SymbTr naming convention
            (makam--form--usul--name--composer).
        Returns
        ----------
        NotImplemented
        """
        if symbtr_name is None:
            symbtr_name = Mu2Reader.get_symbtr_name_from_filepath(score_file)

        return NotImplemented

    @classmethod
    def read_header(cls, score_file, symbtr_name=None):
        """
        Reads the header of the SymbTr-mu2 scores.

        Parameters
        ----------
        score_file : str
            The path of the SymbTr score
        symbtr_name : str, optional
            The name of the score in SymbTr naming convention
            (makam--form--usul--name--composer).
        Returns
        ----------
        dict
            A dictionary storing the symbtr extracted from the header
        list of str
            The names of the columns in the mu2 file
        bool
            True if the symbtr in the mu2 header is valid/consistent,
            False otherwise
        """
        if symbtr_name is None:
            symbtr_name = Mu2Reader.get_symbtr_name_from_filepath(score_file)

        makam_slug = symbtr_name.split('--')[0]
        with open(score_file, encoding='utf-8') as f:
            reader = csv.reader(f, delimiter='\t')
            header_row = next(reader, None)

            header = dict()
            is_tempo_unit_valid = True
            is_key_sig_valid = True
            for row in reader:
                code = int(row[0])
                if code == 50:
                    is_key_sig_valid = Mu2Reader.read_makam_key_signature_row(
                        header, is_key_sig_valid, makam_slug, row, symbtr_name)
                elif code == 51:
                    header['usul'] = {'mu2_name': row[7],
                                      'mertebe': int(row[3]),
                                      'number_of_pulses': int(row[2])}
                elif code == 52:
                    is_tempo_unit_valid = cls._read_tempo_row(
                        row, symbtr_name, header, is_tempo_unit_valid)
                elif code == 56:
                    header['usul']['subdivision'] = {
                        'mertebe': int(row[3]),
                        'number_of_pulses': int(row[2])}
                elif code == 57:
                    header['form'] = {'mu2_name': row[7]}
                elif code == 58:
                    header['composer'] = {'mu2_name': row[7]}
                elif code == 59:
                    header['lyricist'] = {'mu2_name': row[7]}
                elif code == 60:
                    header['title'] = {'mu2_title': row[7]}
                elif code == 62:
                    header['genre'] = 'folk' if row[7] == 'E' else 'classical'
                elif code == 63:
                    header['notation'] = row[7]
                elif code in range(50, 64):
                    warnings.warn('Unparsed code: {0!s}'.
                                  format(' '.join(row)), stacklevel=2)
                else:  # end of header
                    break

        # get the symbtr
        slugs = SymbTrMetadata.get_slugs(symbtr_name)
        for attr in ['makam', 'form', 'usul']:
            SymbTrMetadata.add_attribute_slug(header, slugs, attr)

        header['title']['symbtr_slug'] = slugs['name']
        header['composer']['symbtr_slug'] = slugs['composer']

        # validate the header content
        is_attr_meta_valid = SymbTrMetadata.validate_makam_form_usul(
            header, symbtr_name)

        is_header_valid = (is_tempo_unit_valid and is_attr_meta_valid and
                           is_key_sig_valid)

        return header, header_row, is_header_valid

    @staticmethod
    def read_makam_key_signature_row(header, is_key_sig_valid, makam_slug, row,
                                     symbtr_name):
        header['makam'] = {'mu2_name': row[7]}
        header['key_signature'] = row[8].split('/')
        if not header['key_signature'][0]:
            header['key_signature'] = []

        # validate key signature
        is_key_sig_valid = is_key_sig_valid and SymbTrMetadata. \
            validate_key_signature(header['key_signature'],
                                   makam_slug, symbtr_name)
        return is_key_sig_valid

    @staticmethod
    def _read_tempo_row(row, symbtr_name, header, is_tempo_unit_valid):
        try:
            header['tempo'] = {'value': int(row[4]),
                               'unit': 'bpm'}
        except ValueError:
            # the bpm might be a float for low tempo
            header['tempo'] = {'value': float(row[4]),
                               'unit': 'bpm'}

        if not (int(row[3]) == header['usul']['mertebe'] or
                header['usul']['mu2_name'] == '[Serbest]'):
            warnings.warn('{0!s}: Mertebe and tempo unit are different!'.
                          format(symbtr_name), stacklevel=2)
            is_tempo_unit_valid = False

        return is_tempo_unit_valid B_BAKIYYE = 'slash-flat' B_BMUCENNEP = 'double-slash-flat' B_KMUCENNEP = 'flat' B_KOMA = 'quarter-flat'  # 'flat-down' D_BAKIYYE = 'sharp' D_BMUCENNEP = 'slash-sharp' D_KMUCENNEP = 'slash-quarter-sharp'  # slash-quarter-sharp D_KOMA = 'quarter-sharp'  # quarter-sharp, SWAP 1ST AND 3RD SHARPS N_NATURAL = 'natural' SECTION_LIST = ["1. HANE", "2. HANE", "3. HANE", "4. HANE", "TESLİM",
                "TESLİM ", "MÜLÂZİME", "SERHÂNE", "HÂNE-İ SÂNİ",
                "HÂNE-İ SÂLİS", "SERHANE", "ORTA HANE", "SON HANE",
                "1. HANEYE", "2. HANEYE", "3. HANEYE", "4. HANEYE",
                "KARAR", "1. HANE VE MÜLÂZİME", "2. HANE VE MÜLÂZİME",
                "3. HANE VE MÜLÂZİME", "4. HANE VE MÜLÂZİME",
                "1. HANE VE TESLİM", "2. HANE VE TESLİM",
                "3. HANE VE TESLİM", "4. HANE VE TESLİM", "ARANAĞME",
                "ZEMİN", "NAKARAT", "MEYAN", "SESLERLE NİNNİ",
                "OYUN KISMI", "ZEYBEK KISMI", "GİRİŞ SAZI",
                "GİRİŞ VE ARA SAZI", "GİRİŞ", "FİNAL", "SAZ", "ARA SAZI",
                "SUSTA", "KODA", "DAVUL", "RİTM", "BANDO", "MÜZİK",
                "SERBEST", "ARA TAKSİM", "GEÇİŞ TAKSİMİ", "KÜŞAT",
                "1. SELAM", "2. SELAM", "3. SELAM", "4. SELAM", "TERENNÜM"] class Note:
    def __init__(self, info, verbose=None):
        # base attributes
        self.sira = None
        self.kod = None
        self.nota53 = None
        self.notaae = None
        self.koma53 = None
        self.komaae = None
        self.pay = None
        self.payda = None
        self.ms = None
        self.lns = None
        self.velon = None
        self.soz1 = None
        self.offset = None
        self.nofdivs = 0

        # xml attributes
        self.step = None  # get_pitch
        self.octave = None  # get_pitch
        self.duration = None
        self.type = None  # get_note_type
        self.accidental = None  # get_accidental
        self.alter = None  # get_accidental

        self.lyric = ''
        self.syllabic = None
        self.wordend = 0
        self.lineend = 0

        self.rest = 0  # get_rest
        self.grace = 0  # get_grace
        self.pregrace = 0
        self.dot = 0  # get_note_type
        self.tuplet = 0  # get_note_type
        self.tremolo = 0
        self.glissando = 0
        self.trill = 0
        self.mordent = 0
        self.invertedmordent = 0
        self.mordentlower = 0
        self.grupetto = 0
        self.littlenote = 0
        self.silentgrace = 0

        self.phraseend = 0

        self.graceerror = 0

        if verbose is None:
            verbose = False
        self.verbose = verbose
        self.fetchsymbtrinfo(info)

    def fetchsymbtrinfo(self, info):
        self.sira = info[0]
        self.kod = info[1]
        self.nota53 = info[2]
        self.notaae = info[3]
        self.koma53 = info[4]
        self.komaae = info[5]
        self.pay = info[6]
        self.payda = info[7]
        self.ms = info[8]
        self.lns = info[9]
        self.velon = info[10]
        self.soz1 = info[11]
        self.offset = info[12]
        if self.kod not in ['35', '51', '53', '54', '55']:
            self.get_rest()
            self.get_grace()
            if self.grace == 1 and self.pay != '0':
                self.graceerror = 1

                if self.verbose:
                    print("Warning: GraceError! pay and payda has been "
                          "changed.", self.sira, self.kod, self.pay)

                self.pay = '0'
                self.payda = '0'
            if self.rest == 0:
                self.get_pitch()
            # PAST NOTE: HAS TO FIX HERE (WHATEVER THERE IS TO BE FIXED)
            if self.grace == 0 and self.payda != '0' and self.kod != '0':
                self.get_note_type()
                self.get_accidental()
            self.get_word()

            # ornaments
            if self.kod == '1':
                self.littlenote = 1
            elif self.kod == '4':
                self.glissando = 1
            elif self.kod in ['7', '16']:
                self.tremolo = 1
            elif self.kod in ['12', '32']:
                self.trill = 1
            elif self.kod == '23':
                self.mordent = 1
            elif self.kod == '24':
                self.mordent = 1
                self.mordentlower = 1
            elif self.kod == '43':
                self.invertedmordent = 1
            elif self.kod == '44':
                self.invertedmordent = 1
                self.mordentlower = 1
            elif self.kod == '28':  # xml tag -> TURN
                self.grupetto = 1

        elif self.kod == '51':
            self.lyric = self.soz1

        elif self.kod == '53':  # phrase boundary
            self.phraseend = 1

    def get_rest(self):
        if self.kod == 0 or self.nota53 == "Es":
            self.rest = 1

    def get_grace(self):
        if self.kod == '8':
            self.grace = 1
        elif self.kod == '10':
            self.pregrace = 1
        elif self.kod == '11':
            self.silentgrace = 1

    def get_pitch(self):
        # try:
        self.step = self.notaae[0]
        self.octave = self.notaae[1]
        # except:
        #     raise ValueError('Pitch at line {0:s} with the value "{1:s}" '
        #                      'is invalid.'.format(self.sira, self.notaAE))

    def get_note_type(self):
        # print(self.sira, self.kod, "symbtrnote.get_note_type")
        temp_pay_payda = float(self.pay) / int(self.payda)

        temp_undotted = None
        if temp_pay_payda >= 1.0:
            self.type = 'whole'
            temp_undotted = 1.0
        elif 1.0 > temp_pay_payda >= 1.0 / 2:
            self.type = 'half'
            temp_undotted = 1.0 / 2
        elif 1.0 / 2 > temp_pay_payda >= 1.0 / 4:
            self.type = 'quarter'
            temp_undotted = 1.0 / 4
        elif 1.0 / 4 > temp_pay_payda >= 1.0 / 8:
            self.type = 'eighth'
            temp_undotted = 1.0 / 8
        elif 1.0 / 8 > temp_pay_payda >= 1.0 / 16:
            self.type = '16th'
            temp_undotted = 1.0 / 16
        elif 1.0 / 16 > temp_pay_payda >= 1.0 / 32:
            self.type = '32nd'
            temp_undotted = 1.0 / 32
        elif 1.0 / 32 > temp_pay_payda >= 1.0 / 64:
            self.type = '64th'
            temp_undotted = 1.0 / 64

        # check for tuplets
        if temp_pay_payda == 1.0 / 6:
            self.type = 'quarter'
            temp_undotted = 1.0 / 6
            self.tuplet = 1
        elif temp_pay_payda == 1.0 / 12:
            self.type = 'eighth'
            temp_undotted = 1.0 / 12
            self.tuplet = 1
        elif temp_pay_payda == 1.0 / 24:
            self.type = '16th'
            temp_undotted = 1.0 / 24
            self.tuplet = 1
        # end of tuplets

        if self.tuplet == 0:
            temp_remainder = temp_pay_payda - temp_undotted
            dot_val = temp_undotted / 2.0
            while temp_remainder > 0:
                # print(temp_pay_payda, temp_undotted, temp_remainder,
                # self.sira, self.type)
                self.dot += 1
                temp_remainder = temp_pay_payda - temp_undotted - dot_val
                dot_val += dot_val / 2
            if self.dot > 1 and 0:
                if self.verbose:
                    print("Dots! 1 or more. #ofDots:", self.dot, self.sira)
            # print(sira, temp_pay_payda, temp_undotted, dot_val,
            # temp_remainder)

    def get_accidental(self):
        acc = self.notaae[2:]
        if acc != '':
            if acc in ['#1', '#2']:
                self.accidental = D_KOMA
            elif acc in ['#3', '#4']:
                self.accidental = D_BAKIYYE
            elif acc in ['#5', '#6']:
                self.accidental = D_KMUCENNEP
            elif acc in ['#7', '#8']:
                self.accidental = D_BMUCENNEP
            elif acc in ['b1', 'b2']:
                self.accidental = B_KOMA
            elif acc in ['b3', 'b4']:
                self.accidental = B_BAKIYYE
            elif acc in ['b5', 'b6']:
                self.accidental = B_KMUCENNEP
            elif acc in ['b7', 'b8']:
                self.accidental = B_BMUCENNEP
            # print(self.sira)
            self.alter = ALTER_VALUES[self.accidental]

    def get_word(self):
        # we read the lyrics line even if the composition in instrumental to
        # write the secions and other structural info to the score

        # if self.soz1 not in SECTION_LIST:
        self.lyric = self.soz1
        self.syllabic = ""  # remove NoneType
        if '  ' in self.lyric:  # line endings
            self.lineend = 1
            self.wordend = 1
        elif ' ' in self.lyric:  # word endings
            self.wordend = 1

        if self.lineend or self.wordend:
            self.syllabic = "end"
import copy
import os
from lxml import etree
from ...dataextractor import DataExtractor
from ...reader.mu2 import Mu2Reader
from .symbtrnote import (B_BAKIYYE, B_BMUCENNEP, B_KMUCENNEP, B_KOMA,
                         D_BAKIYYE, D_BMUCENNEP, D_KMUCENNEP, D_KOMA,
                         N_NATURAL, SECTION_LIST, Note)

printflag = 0

tuplet = 0
capitals = []

missing_usuls = []


def get_note_type(n_type, pay, payda):
    global tuplet

    # NEW PART FOR DOTTED NOTES
    temp_pay_payda = float(pay) / int(payda)
    temp_undotted = None
    if temp_pay_payda >= 1.0:
        n_type.text = 'whole'
        temp_undotted = 1.0
    elif 1.0 > temp_pay_payda >= 1.0 / 2:
        n_type.text = 'half'
        temp_undotted = 1.0 / 2
    elif 1.0 / 2 > temp_pay_payda >= 1.0 / 4:
        n_type.text = 'quarter'
        temp_undotted = 1.0 / 4
    elif 1.0 / 4 > temp_pay_payda >= 1.0 / 8:
        n_type.text = 'eighth'
        temp_undotted = 1.0 / 8
    elif 1.0 / 8 > temp_pay_payda >= 1.0 / 16:
        n_type.text = '16th'
        temp_undotted = 1.0 / 16
    elif 1.0 / 16 > temp_pay_payda >= 1.0 / 32:
        n_type.text = '32nd'
        temp_undotted = 1.0 / 32
    elif 1.0 / 32 > temp_pay_payda >= 1.0 / 64:
        n_type.text = '64th'
        temp_undotted = 1.0 / 64

    # check for tuplets
    if temp_pay_payda == 1.0 / 12:
        n_type.text = 'eighth'
        temp_undotted = 1.0 / 12
        tuplet += 1
    elif temp_pay_payda == 1.0 / 24:
        n_type.text = '16th'
        temp_undotted = 1.0 / 24
        tuplet += 1
    # end of tuplets

    # not tuplet, normal or dotted
    nofdots = 0
    timemodflag = 0
    if tuplet == 0:
        temp_remainder = temp_pay_payda - temp_undotted

        dot_val = temp_undotted / 2.0
        while temp_remainder > 0:
            nofdots += 1
            dot_val += dot_val / 2
            break

    # END OF NEW PART FOR DOTTED NOTES
    else:
        timemodflag = 1

    return timemodflag


def get_usul(usul):
    fpath = os.path.join(os.path.dirname(
        os.path.abspath(__file__)), 'makams_usuls', 'usuls_v3_ANSI.txt')

    usul_id = []
    usul_name = []
    num_beats = []
    beat_type = []
    accents = []

    f = open(fpath, encoding='utf-8')

    while 1:
        temp_line = f.readline()

        if len(temp_line) == 0:
            break

        temp_line = temp_line.split('\t')
        temp_line.reverse()

        usul_id.append(temp_line.pop())
        usul_name.append(temp_line.pop())
        num_beats.append(temp_line.pop())
        beat_type.append(temp_line.pop())
        accents.append(temp_line.pop())

    f.close()  # eof filepath read

    # print(usulID[usulID.index(usul)])
    # print(usulName)
    # print(nofBeats[usulID.index(usul)])
    # print(beatType[usulID.index(usul)])
    # print(accents)
    # print(len(usulID),len(usulName),len(nofBeats),len(beatType),len(accents))

    return int(num_beats[usul_id.index(usul)]), int(
        beat_type[usul_id.index(usul)])


def get_accidental_name(alter):
    acc_name = N_NATURAL
    if alter in ['+1', '+2']:
        acc_name = D_KOMA
    elif alter in ['+3', '+4']:
        acc_name = D_BAKIYYE
    elif alter in ['+5', '+6']:
        acc_name = D_KMUCENNEP
    elif alter in ['+7', '+8']:
        acc_name = D_BMUCENNEP
    elif alter in ['-1', '-2']:
        acc_name = B_KOMA
    elif alter in ['-3', '-4']:

        acc_name = B_BAKIYYE