Beispiel #1
0
    def load_preset(self):
        """
        Loads the currently selected preset. Calls its on_first_load function.
        """
        # clears all current units
        self.units.clear()
        self.screen.fill((0, 0, 0))

        bsy = wx.BusyInfo("Initial Loading...")
        self.preset.first_load(self.parser.score)
        bsy = None
        dbg = self.main_frame.debugger.textbox

        # part = self.parser.score.parts[0]   # Gets first track/part of song

        self.should_play = False
        self.next_notes = []

        # get the offset of the first note in the song
        # so we can put it in next_notes
        first_offset = self.notes[0].note.offset
        for n in self.notes:
            if n.note.offset == first_offset:
                ticks = pygame.time.get_ticks()
                new_next_note = [n]
                # new_next_note.append(ticks + util.offet_ms(n.offset, self.tempo))
                try:
                    mts = n.notes.midiTickStart
                except AttributeError:
                    mts = util.offet_ms(n.note.offset, self.tempo)
                try:
                    oq_error = n.note.editorial.offsetQuantizationError
                    mts += oq_error
                except AttributeError:
                    pass

                new_next_note.append(ticks + mts)
                self.next_notes.append(new_next_note)

            if n.note.offset > self.last_offset:
                self.last_offset = n.note.offset

        self.preset_loaded = True
        print("Preset Loaded")
        util.print_line_to_panel(dbg, "\nPreset Loaded\n\n")
Beispiel #2
0
    def update(self):
        """

        """
        if not self.is_playing:
            if self.should_play:
                self.should_play = False
                self.is_playing = True
                self.start_time = pygame.time.get_ticks()
            return
        # determine whether or not to play something
        ticks = pygame.time.get_ticks()

        # see if any current notes are done playing and must be set to off
        # then remove them from current_notes
        for n in self.current_notes:
            if len(n) > 1:
                if ticks >= n[1]:
                    self.player.NoteOff(n[0].note.pitch.midi,
                                        n[0].note.volume.velocity)
                    self.preset.per_note_off(self.screen, n[0])
                    self.current_notes.remove(n)

        if self.next_notes is not None and len(self.next_notes) > 0:
            if ticks >= self.next_notes[0][1]:
                # move next_notes to current_notes
                for n in self.next_notes:
                    new_current_note = [n[0]]
                    # new_current_note.append(None)
                    self.current_notes.append(new_current_note)
                self.next_notes.clear()

                # get the new next notes
                current_offset = self.current_notes[len(self.current_notes) -
                                                    1][0].note.offset
                if current_offset < self.last_offset:
                    for n in self.notes:
                        if n.note.offset > current_offset:
                            new_offset = n.note.offset
                            for m in self.notes:
                                if m.note.offset == new_offset:
                                    ticks = pygame.time.get_ticks()
                                    new_next_note = [m]

                                    oq_error = 0
                                    qlq_error = 0
                                    mts = 0
                                    try:
                                        oq_error = m.note.editorial.offsetQuantizationError
                                    except AttributeError:
                                        pass
                                    try:
                                        qlq_error = m.note.editorial.quarterLengthQuantizationError
                                    except AttributeError:
                                        pass
                                    try:
                                        mts = m.note.midiTickStart
                                    except AttributeError:
                                        pass

                                    offset = util.offet_ms((m.note.offset - current_offset), self.tempo) + \
                                             util.offet_ms(oq_error, self.tempo)
                                    new_next_note.append(ticks + offset)
                                    self.next_notes.append(new_next_note)
                            break

                # if we have reached the last note(s), set next_notes to none so we know not to keep checking for more
                else:
                    self.next_notes.clear()

                # set the ticks length of each current note and
                # play the note and draw it to the screen (via preset)
                for n in self.current_notes:
                    if len(n) < 2:
                        # print("note " + str(n[0].name) + " had no tick value set")
                        length = n[0].note.quarterLength

                        qlq_error = 0
                        try:
                            qlq_error = n[
                                0].note.editorial.quarterLengthQuantizationError
                        except AttributeError:
                            pass
                        length_ms = util.offet_ms(length,
                                                  self.tempo) + util.offet_ms(
                                                      qlq_error, self.tempo)
                        n.append(ticks + length_ms)
                        track = n[0].track
                        # instrument = self.track_instrument_map[track - 1]
                        instrument = self.instrument_map[track - 1]
                        if instrument < 130:
                            if instrument > 0:
                                self.player.set_instrument(instrument - 1)
                            else:
                                self.player.set_instrument(instrument)
                            self.player.NoteOn(n[0].note.pitch.midi,
                                               n[0].note.volume.velocity)
                        else:  # if instrument is not 1-129
                            self.player.set_instrument(20, 10)
                            self.player.NoteOn(n[0].note.pitch.midi,
                                               n[0].note.volume.velocity,
                                               channel=10)

                        self.preset.per_note_on(self.screen, n[0])