def test_ac08_copy_pattern(self): libseq.selectPattern(999) libseq.addNote(0, 60, 123, 2) libseq.copyPattern(999, 998) libseq.selectPattern(998) self.assertEqual(libseq.getNoteDuration(0, 60), 2) self.assertEqual(libseq.getNoteVelocity(0, 60), 123)
def toggle_event(self, step, index): if step < 0 or step >= libseq.getSteps() or index >= len(self.keymap): return note = self.keymap[index]['note'] if libseq.getNoteVelocity(step, note): self.remove_event(step, index) else: self.add_event(step, index) return note
def draw_cell(self, step, row): libseq.isPatternModified() # Avoid refresh redrawing whole grid cellIndex = row * libseq.getSteps( ) + step # Cells are stored in array sequentially: 1st row, 2nd row... if cellIndex >= len(self.cells): return note = self.keymap[row + self.keymap_offset]["note"] velocity_colour = libseq.getNoteVelocity(step, note) if velocity_colour: velocity_colour = 70 + velocity_colour elif libseq.getScale() == 1: # Draw tramlines for white notes in chromatic scale key = note % 12 if key in (0, 2, 4, 5, 7, 9, 11): # White notes # if key in (1,3,6,8,10): # Black notes velocity_colour += 30 else: # Draw tramlines for odd rows in other scales and maps if (row + self.keymap_offset) % 2: velocity_colour += 30 duration = libseq.getNoteDuration(step, note) if not duration: duration = 1 fill_colour = "#%02x%02x%02x" % (velocity_colour, velocity_colour, velocity_colour) cell = self.cells[cellIndex] coord = self.get_cell(step, row, duration) if cell: # Update existing cell self.grid_canvas.itemconfig(cell, fill=fill_colour) self.grid_canvas.coords(cell, coord) else: # Create new cell cell = self.grid_canvas.create_rectangle( coord, fill=fill_colour, width=0, tags=("%d,%d" % (step, row), "gridcell", "step%d" % step)) self.grid_canvas.tag_bind(cell, '<ButtonPress-1>', self.on_grid_press) self.grid_canvas.tag_bind(cell, '<ButtonRelease-1>', self.on_grid_release) self.grid_canvas.tag_bind(cell, '<B1-Motion>', self.on_grid_drag) self.cells[cellIndex] = cell if step + duration > libseq.getSteps(): self.grid_canvas.itemconfig("lastnotetext%d" % row, text="+%d" % (duration - libseq.getSteps() + step), state="normal")
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 on_grid_press(self, event): if self.parent.lst_menu.winfo_viewable(): self.parent.hide_menu() return if self.parent.param_editor_item != None: self.parent.hide_param_editor() return self.grid_drag_start = event try: col, row = self.grid_canvas.gettags( self.grid_canvas.find_withtag(tkinter.CURRENT))[0].split(',') except: return note = self.keymap[self.keymap_offset + int(row)]["note"] step = int(col) if step < 0 or step >= libseq.getSteps(): return self.drag_start_velocity = libseq.getNoteVelocity(step, note) self.drag_start_duration = libseq.getNoteDuration(step, note) self.drag_start_step = int(event.x / self.step_width) if not self.drag_start_velocity: self.play_note(note) self.select_cell(int(col), self.keymap_offset + int(row))
def test_ac07_transpose(self): libseq.selectPattern(999) libseq.addNote(0, 60, 123, 2) libseq.transpose(5) self.assertEqual(libseq.getNoteDuration(0, 65), 2) self.assertEqual(libseq.getNoteVelocity(0, 65), 123)
def test_ac05_set_note_velocity(self): libseq.selectPattern(999) self.assertTrue(libseq.addNote(0, 60, 100, 4)) libseq.setNoteVelocity(0, 60, 123) self.assertEqual(libseq.getNoteVelocity(0, 60), 123)
def test_ac04_add_note_too_long(self): libseq.selectPattern(999) self.assertTrue(libseq.addNote(0, 60, 100, 4)) self.assertFalse(libseq.addNote(0, 60, 100, 200)) self.assertEqual(libseq.getNoteVelocity(0, 60), 100) self.assertEqual(libseq.getNoteDuration(0, 60), 4)