示例#1
0
 def test_remove_last_measure_does_not_removes_last_measure_if_one_measure(
         self):
     score_service.remove_last_measure()
     score_service.remove_last_measure()
     length_before = score_service.get_staff_length()
     score_service.remove_last_measure()
     length_after = score_service.get_staff_length()
     self.assertEqual(length_before, 1)
     self.assertEqual(length_after, 1)
示例#2
0
 def _handle_remove_notation(self, selected):
   self._update_error_label()
   try:
     measure_index = int(selected[1:2])
     notation_index = int(selected[5:6])
     score_service.remove_notation(measure_index - 1, notation_index - 1)
     self._selected_entry.update()
     self._update_score_view(measure_index / score_service.get_staff_length())
   except:
     pass
示例#3
0
 def _handle_add_rest(self, measure, length):
   self._update_error_label()
   try:
     is_success = score_service.add_rest(measure, length)
     if is_success == True:
       self._update_score_view((int(measure) - 1) / score_service.get_staff_length())
     elif is_success == 'No space':
       self._error_label.grid(row=0, column=8)
   except:
     pass
示例#4
0
 def test_remove_last_measure_removes_last_measure(self):
     length_before = score_service.get_staff_length()
     score_service.remove_last_measure()
     length_after = score_service.get_staff_length()
     self.assertEqual(length_after, length_before - 1)
示例#5
0
 def test_add_measure_increases_length_of_measures(self):
     staff_length_first = score_service.get_staff_length()
     score_service.add_measure()
     staff_length_after = score_service.get_staff_length()
     self.assertEqual(staff_length_after, staff_length_first + 1)
示例#6
0
    def _show_score(self):
        canvas = tk.Canvas(master=self._score_frame,
                           width=700,
                           height=1000,
                           confine=True)

        x_position = 50
        # Clef
        canvas.create_image(x_position,
                            105,
                            image=self._clef,
                            anchor=tk.constants.NW)
        x_position += 100
        # Key signature
        key_signature = score_service.get_key_signature()
        clef = score_service.get_clef()
        if key_signature != 'C/a':
            if clef == 'G':
                if key_signature == 'F/d':
                    canvas.create_image(x_position,
                                        150,
                                        image=self._flat,
                                        anchor=tk.constants.NW)
                if key_signature == 'G/e':
                    canvas.create_image(x_position,
                                        100,
                                        image=self._sharp,
                                        anchor=tk.constants.NW)
            else:
                if key_signature == 'F/d':
                    canvas.create_image(x_position,
                                        180,
                                        image=self._flat,
                                        anchor=tk.constants.NW)
                if key_signature == 'G/e':
                    canvas.create_image(x_position,
                                        130,
                                        image=self._sharp,
                                        anchor=tk.constants.NW)
            x_position += 40
        # Time signature
        canvas.create_image(x_position,
                            140,
                            image=self._time_signature,
                            anchor=tk.constants.NW)

        #Notations
        notation_position = x_position + 60
        notation_gap = 75

        measure_count = score_service.get_staff_length()

        for i in range(measure_count):
            measure = self._score.get_staff().get_measures()[i]

            for notation in measure.get_notations():
                length = notation.get_length()

                if notation.is_note():  #note
                    pitch = notation.get_pitch()
                    pitch_index = PITCHES.index(pitch)
                    if (measure.get_clef().get_clef() == 'G'):
                        note_position = PITCH_POSITIONS_IN_G_CLEF[pitch_index]
                    elif (measure.get_clef().get_clef() == 'F'):
                        note_position = PITCH_POSITIONS_IN_F_CLEF[pitch_index]
                    if length == 2:
                        canvas.create_image(notation_position,
                                            note_position,
                                            image=self._half_note,
                                            anchor=tk.constants.NW)
                    elif length == 4:
                        canvas.create_image(notation_position,
                                            note_position,
                                            image=self._quarter_note,
                                            anchor=tk.constants.NW)
                    elif length == 8:
                        canvas.create_image(notation_position,
                                            note_position,
                                            image=self._eight_note,
                                            anchor=tk.constants.NW)
                    elif length == 16:
                        canvas.create_image(notation_position,
                                            note_position,
                                            image=self._sixteenth_note,
                                            anchor=tk.constants.NW)

                    if note_position <= 20:  # top ledger lines
                        ledger_line_position = 120
                        while (ledger_line_position - 100 >= note_position):
                            canvas.create_line(notation_position + 10,
                                               ledger_line_position,
                                               notation_position + 65,
                                               ledger_line_position,
                                               fill='black')
                            ledger_line_position -= 30

                    if note_position >= 200:  # bottom ledger lines
                        ledger_line_position = 300
                        while (ledger_line_position - 100 <= note_position):
                            canvas.create_line(notation_position + 10,
                                               ledger_line_position,
                                               notation_position + 65,
                                               ledger_line_position,
                                               fill='black')
                            ledger_line_position += 30

                else:  #rest
                    if length == 2:
                        canvas.create_image(notation_position,
                                            152,
                                            image=self._half_rest,
                                            anchor=tk.constants.NW)
                    elif length == 4:
                        canvas.create_image(notation_position,
                                            152,
                                            image=self._quarter_rest,
                                            anchor=tk.constants.NW)
                    elif length == 8:
                        canvas.create_image(notation_position,
                                            152,
                                            image=self._eight_rest,
                                            anchor=tk.constants.NW)
                    elif length == 16:
                        canvas.create_image(notation_position,
                                            152,
                                            image=self._sixteenth_rest,
                                            anchor=tk.constants.NW)

                notation_position += notation_gap
            if i == measure_count - 1:
                break
            canvas.create_line(notation_position + 25, 150,
                               notation_position + 25, 270)
            notation_position += 25

        endline = notation_position + 50

        # Staff
        canvas.create_line(50, 150, endline, 150, fill='black')
        canvas.create_line(50, 180, endline, 180, fill='black')
        canvas.create_line(50, 210, endline, 210, fill='black')
        canvas.create_line(50, 240, endline, 240, fill='black')
        canvas.create_line(50, 270, endline, 270, fill='black')
        # Starting diagonal line
        canvas.create_line(50, 150, 50, 270, fill='black')
        # Ending diagonal lines
        canvas.create_line(endline - 10, 150, endline - 10, 270, fill='black')
        canvas.create_rectangle(endline, 150, endline + 10, 270, fill='black')

        # Horizontal scroll
        scroll_x = tk.Scrollbar(self._score_frame,
                                orient="horizontal",
                                command=canvas.xview)
        scroll_x.grid(row=1, column=0, sticky="ews", columnspan=3)
        canvas.configure(xscrollcommand=scroll_x.set)
        canvas.configure(scrollregion=canvas.bbox("all"))

        canvas.xview_moveto(self._scroll_position)

        canvas.grid(row=1, column=0, sticky='esw', columnspan=3, padx=25)