def assert_beats_in_pattern(self):
     value = self.parent.get_param('Beats in pattern', 'value')
     if libseq.getLastStep() >= libseq.getStepsPerBeat() * value:
         self.zyngui.show_confirm(
             "Reducing beats in pattern will truncate pattern",
             self.set_beats_in_pattern)
     else:
         self.set_beats_in_pattern()
Ejemplo n.º 2
0
 def check_pattern(self, beat_type, steps_per_beat, beats_in_pattern):
     steps_in_pattern = beats_in_pattern * steps_per_beat
     clocks_per_step = 24 / steps_per_beat
     self.assertEqual(libseq.getSteps(), steps_in_pattern)
     self.assertEqual(libseq.getBeatType(), beat_type)
     self.assertEqual(libseq.getStepsPerBeat(), steps_per_beat)
     self.assertEqual(libseq.getBeatsInPattern(), beats_in_pattern)
     self.assertEqual(libseq.getClocksPerStep(), clocks_per_step)
     self.assertEqual(libseq.getPatternLength(libseq.getPatternIndex()),
                      clocks_per_step * steps_in_pattern)
 def export_smf(self, params):
     smf = libsmf.addSmf()
     tempo = libseq.getTempo()
     libsmf.addTempo(smf, 0, tempo)
     ticks_per_step = libsmf.getTicksPerQuarterNote(
         smf) / libseq.getStepsPerBeat()
     for step in range(libseq.getSteps()):
         time = int(step * ticks_per_step)
         for note in range(128):
             duration = libseq.getNoteDuration(step, note)
             if duration == 0:
                 continue
             duration = int(duration * ticks_per_step)
             velocity = libseq.getNoteVelocity(step, note)
             libsmf.addNote(smf, 0, time, duration, self.channel, note,
                            velocity)
     libsmf.setEndOfTrack(smf, 0, int(libseq.getSteps() * ticks_per_step))
     zynsmf.save(
         smf, "/zynthian/zynthian-my-data/capture/pattern%d_%s.mid" %
         (self.pattern, datetime.now()))
 def draw_grid(self):
     clear_grid = (self.redraw_pending == 2)
     self.redraw_pending = 0
     if libseq.getSteps() == 0:
         return  #TODO: Should we clear grid?
     if self.keymap_offset > len(self.keymap) - self.zoom:
         self.keymap_offset = len(self.keymap) - self.zoom
     if self.keymap_offset < 0:
         self.keymap_offset = 0
     font = tkFont.Font(family=zynthian_gui_config.font_topbar[0],
                        size=self.fontsize)
     if clear_grid:
         self.grid_canvas.delete(tkinter.ALL)
         self.step_width = (self.grid_width - 2) / libseq.getSteps()
         self.draw_pianoroll()
         self.cells = [None] * self.zoom * libseq.getSteps()
         self.play_canvas.coords(
             "playCursor", 1 + self.playhead * self.step_width, 0,
             1 + self.playhead * self.step_width + self.step_width,
             PLAYHEAD_HEIGHT)
     # Draw cells of grid
     self.grid_canvas.itemconfig("gridcell", fill="black")
     # Redraw gridlines
     self.grid_canvas.delete("gridline")
     if libseq.getStepsPerBeat():
         for step in range(0,
                           libseq.getSteps() + 1, libseq.getStepsPerBeat()):
             self.grid_canvas.create_line(step * self.step_width,
                                          0,
                                          step * self.step_width,
                                          self.zoom * self.row_height - 1,
                                          fill=GRID_LINE,
                                          tags=("gridline"))
     # Delete existing note names
     self.piano_roll.delete("notename")
     for row in range(0, self.zoom):
         index = row + self.keymap_offset
         if (index >= len(self.keymap)):
             break
         if clear_grid:
             # Create last note labels in grid
             self.grid_canvas.create_text(
                 self.grid_width - self.select_thickness,
                 int(self.row_height * (self.zoom - row - 0.5)),
                 state="hidden",
                 tags=("lastnotetext%d" % (row), "lastnotetext"),
                 font=font,
                 anchor="e")
         self.draw_row(index)
         # Update pianoroll keys
         id = "row%d" % (row)
         try:
             name = self.keymap[index]["name"]
         except:
             name = None
         try:
             colour = self.keymap[index]["colour"]
         except:
             colour = "white"
         self.piano_roll.itemconfig(id, fill=colour)
         if name:
             self.piano_roll.create_text(
                 (2, self.row_height * (self.zoom - row - 0.5)),
                 text=name,
                 font=font,
                 anchor="w",
                 fill=CANVAS_BACKGROUND,
                 tags="notename")
         if self.keymap[index]['note'] % 12 == libseq.getTonic():
             self.grid_canvas.create_line(
                 0, (self.zoom - row) * self.row_height,
                 self.grid_width, (self.zoom - row) * self.row_height,
                 fill=GRID_LINE,
                 tags=("gridline"))
     # Set z-order to allow duration to show
     if clear_grid:
         for step in range(libseq.getSteps()):
             self.grid_canvas.tag_lower("step%d" % step)
     self.select_cell()
 def get_steps_per_beat_index(self):
     steps_per_beat = libseq.getStepsPerBeat()
     for index in range(len(STEPS_PER_BEAT)):
         if STEPS_PER_BEAT[index] >= steps_per_beat:
             return index
     return index