Ejemplo n.º 1
0
    def test_same_tone_different_name(self):
        """n2 has the same tone, but as an enharmonic of n1."""

        n1 = note.Note('E#6', True)
        n2 = note.Note('F4', True)
        actual = n1.different_octave(n2)
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 2
0
    def test_both_before_n1_before_n2(self):
        """Both notes come before C, n1 comes before n2."""

        n1 = note.Note('A#6', True)
        n2 = note.Note('B4', True)
        actual = n1.different_octave(n2)
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 3
0
    def test_both_before_n1_after_n2(self):
        """Both notes come before C, n1 comes after n2."""

        n1 = note.Note('Cb210', True)
        n2 = note.Note('A4', True)
        actual = n1.different_octave(n2)
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 4
0
    def test_both_after_n1_after_n2(self):
        """Both notes come after C, n1 comes after n2."""

        n1 = note.Note('G8', True)
        n2 = note.Note('Fb5', True)
        actual = n1.different_octave(n2)
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 5
0
    def test_after_C_to_before_C(self):
        """n1 has tone after C, n2 has tone before C."""

        n1 = note.Note('F4', True)
        n2 = note.Note('Bb3', True)
        actual = n1.different_octave(n2)
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 6
0
    def test_C(self):
        """n1 has tone C and n2 has tone != C."""

        n1 = note.Note('C3', True)
        n2 = note.Note('A3', True)
        actual = n1.different_octave(n2)
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 7
0
    def test_same_tone_same_name(self):
        """n2 has the same tone as n1."""

        n1 = note.Note('F4', True)
        n2 = note.Note('F4', True)
        actual = n1.different_octave(n2)
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 8
0
def read_midi(filename):
    """
    Returns a list of tracks.
    Each track is a list containing 128 lists of notes.
    """
    midi_tracks = midi.read_midifile(filename)
    resolution = midi_tracks.resolution
    tempo_bpm = 120.0  # may be changed repeatedly in the loop
    note_tracks = []
    for t_index, t in enumerate(midi_tracks):
        notes_pitchwise = [[] for i in range(128)]
        total_ticks = 0
        for elem in t:
            total_ticks += elem.tick
            if elem.name in ["Note On", "Note Off"]:
                pitch = elem.data[0]
                if is_note_on(elem):
                    n = note.Note(velocity=elem.data[1],
                                  pitch=pitch,
                                  start_ticks=total_ticks,
                                  track=t_index)
                    notes_pitchwise[pitch].append(n)
                else:
                    for n in reversed(notes_pitchwise[pitch]):
                        if not n.finished:
                            n.end_ticks = total_ticks
                            n.finished = True
                        else:
                            break
            elif elem.name == "Set Tempo":
                tempo_bpm = elem.get_bpm()
        note_tracks.append(notes_pitchwise)
    return note_tracks, tempo_bpm, resolution
def parseNote(fileName):
    tree = ET.parse(fileName)
    enExport = tree.getroot()
    noteTree = enExport[0]
    title = noteTree.findall('title')[0].text
    author = noteTree.findall('note-attributes')[0].findall('author')[0].text
    created = noteTree.findall('created')[0].text
    updated = noteTree.findall('updated')[0].text

    contentStr = noteTree.findall('content')[0].text
    contentStr = contentStr.replace(
        """<?xml version="1.0" encoding="UTF-8" standalone="no"?>""", "")
    contentStr = contentStr.replace(
        """<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">""",
        "")
    contentTree = ET.fromstring(contentStr)

    resourceListTree = noteTree.findall('resource')

    noteObj = note.Note()
    noteObj.author = author
    noteObj.title = title
    noteObj.created = created
    noteObj.updated = updated
    noteObj.contentTree = contentTree
    noteObj.resources = resourceListTree

    for tagNode in noteTree.findall('tag'):
        noteObj.addTag(tagNode.text)

    return noteObj
Ejemplo n.º 10
0
 def select_all(self):
     self.cur.execute(
         "select noteid, notets, notetext from notes order by notets asc")
     notes = []
     for row in self.cur.fetchall():
         notes.append((row[0], note.Note(row[2], row[1])))
     return notes
Ejemplo n.º 11
0
 def create_note(self, button):
     if self.sidebar.add_item("New Note", self.id):
         self.editor.set_text("")
         note_item = note.Note("New Note", "", [])
         parent_id = self.sidebar.get_id(self.sidebar.get_selected())
         self.db[parent_id]['notes'][self.id] = note_item
         self.id += 1
Ejemplo n.º 12
0
 def new_note(self, memo: str, tags=''):
     """
     Create a new note.
     """
     tags = tags.split(', ')
     new_note = note.Note(memo, tags)
     self.notes.append(new_note)
Ejemplo n.º 13
0
    def build_chord(self, mode: str, size: int = 3) -> None:
        """Modify self.notes to include size notes of a mode chord in the key
        of self.root_note.tone.

        Precondition: size > 0

        >>> n = note.Note('G3', True)
        >>> c = Chord(n)
        >>> c.build_chord('major', 4)
        >>> str(c)
        'G major: G3, B3, D4, G4'
        """

        # Initialize a data_set to gain access to chord writing methods.
        data_set = data.Data()

        self.mode = mode
        self.size += size
        octave = self.root_note.octave
        # Append the first note to self.notes.
        self.notes.append(self.root_note)

        for i in range(1, size):
            # Get the tone of the next note.
            tone = eval(
                'self.' +
                data_set.chord_to_method[self.mode].format('i', 'self.key'))
            n = note.Note(tone + str(octave), False)

            # If next tone appears in the next octave, increment octave by 1.
            if n.different_octave(self.notes[i - 1]):
                n.octave += 1
                octave += 1

            self.notes.append(n)
Ejemplo n.º 14
0
    def test_neutral(self):
        """The Chord is neutral."""

        n = note.Note('F#4', True)
        c = chord.Chord(n)
        c.remove_notes('major 7')

        self.assertEqual(c.notes, [])
Ejemplo n.º 15
0
    def test_1_note_keep(self):
        """The Chord has 1 note that is NOT removed."""

        n = note.Note('A#4', True)
        c = chord.Chord(n)
        c.build_chord('major', 1)
        c.remove_notes('perfect 5')

        self.assertEqual(c.notes, [n])
Ejemplo n.º 16
0
    def test_1_note_remove(self):
        """The Chord has 1 note that is removed."""

        n = note.Note('Bb2', True)
        c = chord.Chord(n)
        c.build_chord('minor', 1)
        c.remove_notes('perfect 1')

        self.assertEqual(c.notes, [])
Ejemplo n.º 17
0
    def test_neutral(self):
        """The Chord is neutral."""

        n = note.Note('G#4', True)
        c = chord.Chord(n)

        actual = c.is_crunchy()
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 18
0
    def test_many_notes_no_crunch(self):
        """The Chord contains more than 1 note and none are dissonant with each other."""

        n = note.Note('Gb3', True)
        c = chord.Chord(n)
        c.build_chord('minor', 7)

        actual = c.is_crunchy()
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 19
0
    def test_one_note(self):
        """self.notes contains 1 note."""

        n = note.Note('G3', True)
        c = chord.Chord(n)
        c.build_chord('minor', 1)

        actual = c.correct_location(0, 'C')
        expected = 1
        self.assertEqual(actual, expected)
Ejemplo n.º 20
0
    def test_2_notes_no_crunch(self):
        """The Chord contains 2 notes that are NOT dissonant."""

        n = note.Note('Fx4', True)
        c = chord.Chord(n)
        c.build_chord('augmented', 2)

        actual = c.is_crunchy()
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 21
0
    def test_many_notes_crunch(self):
        """The Chord contains more than 1 note and at least 2 are dissonant with each other."""

        n = note.Note('C3', True)
        c = chord.Chord(n)
        c.build_chord('major suspended 4')

        actual = c.is_crunchy()
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 22
0
    def test_one_note(self):
        """The Chord contains one note."""

        n = note.Note('Ab3', True)
        c = chord.Chord(n)
        c.build_chord('major suspended 2', 1)

        actual = c.is_crunchy()
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 23
0
    def test_2_notes_crunch(self):
        """The Chord contains 2 notes that are dissonant."""

        n = note.Note('G3', True)
        c = chord.Chord(n)
        c.build_chord('major suspended 2', 2)

        actual = c.is_crunchy()
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 24
0
    def test_fill_no_octave(self):
        """The Chord contains more than 1 non-root note, but only 1 root octave."""

        n = note.Note('Bb3', True)
        c = chord.Chord(n)
        c.build_chord('augmented', 3)

        actual = c.is_rich()
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 25
0
    def test_rich(self):
        """The Chord contains multiple octaves with 2 or more notes in between."""

        n = note.Note('A#4', True)
        c = chord.Chord(n)
        c.build_chord('major suspended 24', 6)

        actual = c.is_rich()
        expected = True
        self.assertEqual(actual, expected)
Ejemplo n.º 26
0
    def test_one_note(self):
        """The Chord has one note."""

        n = note.Note('Fx4', True)
        c = chord.Chord(n)
        c.build_chord('major', 1)

        actual = c.is_rich()
        expected = False
        self.assertEqual(actual, expected)
Ejemplo n.º 27
0
    def test_already_exists(self):
        """Notes with argument tone already exist in a Chord."""

        n = note.Note('C3', True)
        c = chord.Chord(n)
        c.build_chord('major', 5)

        actual = c.correct_location(0, 'G')
        expected = 5
        self.assertEqual(actual, expected)
Ejemplo n.º 28
0
    def test_2_notes_middle(self):
        """self.notes has 2 notes and a Note with tone add_tone should be added in between the 2 notes."""

        n = note.Note('B2', True)
        c = chord.Chord(n)
        c.build_chord('major', 2)

        actual = c.correct_location(0, 'C#')
        expected = 1
        self.assertEqual(actual, expected)
Ejemplo n.º 29
0
    def test_start_at_end(self):
        """Start searching from the last index in the Chord."""

        n = note.Note('Ab3', True)
        c = chord.Chord(n)
        c.build_chord('minor', 6)

        actual = c.correct_location(5, 'G')
        expected = 6
        self.assertEqual(actual, expected)
Ejemplo n.º 30
0
    def test_many_notes_middle(self):
        """self.notes has more than 2 notes and a Note with tone add_tone should be added after the first pair."""

        n = note.Note('C#3', True)
        c = chord.Chord(n)
        c.build_chord('diminished', 4)

        actual = c.correct_location(0, 'F#')
        expected = 2
        self.assertEqual(actual, expected)