Пример #1
0
def createVoice(voiceString):
    if (voiceString == None or voiceString == ""):
        return scorelib.Voice(None, None)

    name = None
    range = None

    rRange = re.compile(r"(.+--.+?)[,;] (.*)")
    mRange = rRange.search(voiceString)

    if (mRange):
        range = mRange.group(1)
        name = mRange.group(2)
    else:
        name = voiceString

    return scorelib.Voice(name, range)
Пример #2
0
def insert_voice(voice, c, number, com_id):
    if voice is None:
        voice = scorelib.Voice(None, None)
    c.execute("select * from voice where name IS ? and range IS ? and number IS ? and score IS ?", (voice.name, voice.range, number, com_id))
    res = c.fetchone()
    if res is None:
        c.execute("insert into voice(number, score, range, name) values (?, ?, ?, ?)", (number, com_id, voice.range, voice.name))
        return c.lastrowid
    return res[0]
Пример #3
0
def parse_voices(cursor, composition_id):
    result = []
    voices = cursor.execute(
        "SELECT range, name FROM voice WHERE voice.score=? ORDER BY voice.number ASC",
        (composition_id, )).fetchall()
    for voice in voices:
        voice_name = voice[1]
        voice_range = voice[0]
        result.append(scorelib.Voice(voice_name, voice_range))
    return result
Пример #4
0
def create_voice(voice_string):
    voice = sc.Voice(None, None)

    ranger = re.match("(\(?\w*?\)?\w*-{1,2}\w*),?;?[\s]?(.*)?", voice_string)
    if ranger:
        voice.range = ranger.group(1).strip()
        if ranger.group(2).strip() != "":
            voice.name = ranger.group(2).strip()

    else:
        voice.name = voice_string

    return voice
Пример #5
0
def getPrints(listOfPrintIds):
    prints = []

    for id in listOfPrintIds:
        composers = []
        editors = []
        voices = {}

        cur.execute(
            '''SELECT print.id, print.partiture, edition.id, edition.name, score.id, score.name, score.incipit, score.key, score.genre, score.year FROM print 
		JOIN edition ON edition.id = print.edition
		JOIN score ON score.id = edition.score WHERE print.id = ? ''', (id, ))
        rowMain = cur.fetchone()

        editionId = rowMain[2]
        compositionId = rowMain[4]

        cur.execute(
            '''SELECT number, range, name FROM voice WHERE score = ? ''',
            (compositionId, ))
        for voice in cur:
            voices[voice[0]] = scorelib.Voice(voice[2], voice[1])

        cur.execute(
            '''SELECT name, born, died FROM score_author JOIN person ON person.id = score_author.composer WHERE score_author.score = ? ''',
            (compositionId, ))
        for comp in cur:
            composers.append(scorelib.Person(comp[0], comp[1], comp[2]))

        cur.execute(
            '''SELECT name, born, died FROM edition_author JOIN person ON person.id = edition_author.editor WHERE edition_author.edition = ? ''',
            (editionId, ))
        for edi in cur:
            editors.append(scorelib.Person(edi[0], edi[1], edi[2]))

        composition = scorelib.Composition(rowMain[5], rowMain[6], rowMain[7],
                                           rowMain[8], voices, composers)
        setattr(composition, "composition year", rowMain[9])
        edition = scorelib.Edition(rowMain[3], composition, editors)

        if (rowMain[1] == "Y" or rowMain[1] == "y"):
            partiture = True
        else:
            partiture = False
        printInstance = scorelib.Print(edition, partiture)
        setattr(printInstance, "print number", rowMain[0])
        prints.append(printInstance)
    return prints
Пример #6
0
def processVoiceLine(voiceLine):
    rc = re.compile(r"(.+--.+?)[,;] (.*)")
    rangeMatch = rc.match(voiceLine)

    range = None
    name = None

    if (rangeMatch):
        range = rangeMatch.group(1)
        name = rangeMatch.group(2)
    elif (voiceLine != ""):
        name = voiceLine

    if (range == None and name == None):
        return None
    return scorelib.Voice(name, range)
Пример #7
0
def getAllPrints():
    dbFilename = "scorelib.dat"

    conn = sqlite3.connect(dbFilename)
    cur = conn.cursor()

    persons = []
    compositions = []
    editions = []
    prints = []

    for row in cur.execute('SELECT * FROM score'):
        compositions.append(
            scorelib.Composition(row[1], row[4], row[3], row[2], row[5], [],
                                 []))

    for row in cur.execute('SELECT * FROM person'):
        persons.append(scorelib.Person(row[3], row[1], row[2]))

    for row in cur.execute('SELECT * FROM voice'):
        voice = scorelib.Voice(row[4], row[3])
        if (len(compositions[row[2] - 1].Voices) < row[1] - 1):
            compositions[row[2] - 1].Voices.append(None)
        if (len(compositions[row[2] - 1].Voices) < row[1] - 1):
            compositions[row[2] - 1].Voices.append(None)
        if (len(compositions[row[2] - 1].Voices) < row[1] - 1):
            compositions[row[2] - 1].Voices.append(None)
        if (len(compositions[row[2] - 1].Voices) < row[1] - 1):
            compositions[row[2] - 1].Voices.append(None)
        compositions[row[2] - 1].Voices.append(voice)

    for row in cur.execute('SELECT * FROM edition'):
        edition = scorelib.Edition(compositions[row[1] - 1], [], row[2])
        editions.append(edition)

    for row in cur.execute('SELECT * FROM score_author'):
        compositions[row[1] - 1].Composer.append(persons[row[2] - 1])

    for row in cur.execute('SELECT * FROM edition_author'):
        editions[row[1] - 1].Editor.append(persons[row[2] - 1])

    for row in cur.execute('SELECT * FROM print'):
        part = True if row[1] == "Y" else False
        prints.append(scorelib.Print(editions[row[2] - 1], row[0], part))

    return prints
Пример #8
0
def convert_voices(voices_from_db_tuples):
    voices_from_db_list = []
    for voice_db in voices_from_db_tuples:
        voices_from_db_list.append(scorelib.Voice(voice_db[0], voice_db[1]))
    return voices_from_db_list
Пример #9
0
def save_score(cur, composition):
    params = []
    #params.append(composition.name)

    if composition.name is None:
        name_query = 'name is NULL'
    else:
        name_query = 'name=?'
        params.append(composition.name)

    if composition.genre is None:
        genre_query = 'genre is NULL'
    else:
        genre_query = 'genre=?'
        params.append(composition.genre)

    if composition.key is None:
        key_query = 'key is NULL'
    else:
        key_query = 'key=?'
        params.append(composition.key)
    if composition.incipit is None:
        incipit_query = 'incipit is NULL'
    else:
        incipit_query = 'incipit=?'
        params.append(composition.incipit)
    if composition.year is None:
        year_query = 'year is NULL'
    else:
        year_query = 'year=?'
        params.append(composition.year)

    cur.execute(
        'SELECT id FROM score WHERE ' + name_query + ' and ' + genre_query +
        ' and ' + key_query + ' and ' + incipit_query + ' and ' + year_query,
        (params))

    row = cur.fetchone()

    if row is None:
        cur.execute(
            'INSERT INTO score (name, genre, key, incipit, year) VALUES (?, ?, ?, ?, ?)',
            (composition.name, composition.genre, composition.key,
             composition.incipit, composition.year))
        return cur.lastrowid
    else:
        tmp_composition = scorelib.Composition()
        tmp_composition.name = composition.name
        tmp_composition.genre = composition.genre
        tmp_composition.key = composition.key
        tmp_composition.incipit = composition.incipit
        tmp_composition.year = composition.year

        cur.execute(
            'SELECT name from person JOIN score_author ON person.id=score_author.composer WHERE score=?',
            (row[0], ))

        result = cur.fetchall()
        if result is not None:
            for composer in result:
                tmp_composer = scorelib.Person()
                tmp_composer.name = composer[0]
                tmp_composition.authors.append(tmp_composer)

        cur.execute('SELECT number, name, range from voice WHERE score=?',
                    (row[0], ))

        result = cur.fetchall()

        if result is not None:
            for i in range(0, len(result)):
                tmp_voice = scorelib.Voice()
                tmp_voice.number = int(result[i][0])
                tmp_voice.name = result[i][1]
                tmp_voice.range = result[i][2]
                tmp_composition.voices.append(tmp_voice)

        if composition.__eq__(tmp_composition):
            return row[0]
        else:
            cur.execute(
                'INSERT INTO score (name, genre, key, incipit, year) VALUES (?, ?, ?, ?, ?)',
                (composition.name, composition.genre, composition.key,
                 composition.incipit, composition.year))
            return cur.lastrowid