def mouseReleaseEvent(self, ev): if self.pressed == ev.scenePos(): x, y = self.get_box_coords(ev) if self.ui.instruments.count() == 0 or self.ui.progressions.count() == 0: return if x >= 0 and y >= 0: self.ui.instruments.setCurrentRow(y) instrument = self.ui.instruments.item(y) instr = str(instrument.text()).split() params = Options.parse_instrument_params(instr[1:]) play, stop = [], [] if 'must_not_play' in params: stop = [ int(z) for z in params['must_not_play'].split("-") ] if 'must_play' in params: play = [ int(z) for z in params['must_play'].split("-")] if x in play: play.remove(x) if x not in stop and not self.plays(params, x, True): stop.append(x) elif x in stop: stop.remove(x) if x not in play: play.append(x) else: if not self.plays(params, x, True): play.append(x) else: stop.append(x) stop = [ str(x) for x in stop ] play = [ str(x) for x in play ] if play != []: play.sort() params['must_play'] = "-".join(play) else: if params.has_key('must_play'): del params['must_play'] if stop != []: stop.sort() params['must_not_play'] = "-".join(stop) else: if params.has_key('must_not_play'): del params['must_not_play'] instrument.setText("%s { %s }" % (instr[0], " ".join([ "%s:%s" % (str(x), str(params[x])) for x in params ]) )) self.update() elif y >= 0: self.ui.instruments.setCurrentRow(y) self.update()
def load_instrument(self, instr_str): instr_str = str(instr_str) parts = instr_str.split(" ") index = combo_index_by_text(self.ui.algorithm, parts[0]) if index > 0: self.ui.algorithm.setCurrentIndex(index) params = Options.parse_instrument_params(parts[1:]) i = getattr(Musicians, parts[0])(params) self.ui.stepstart.setValue(i.start) self.ui.stepend.setValue(i.end) self.ui.step.setValue(i.step) self.ui.end.setValue(i.global_end) self.ui.channel.setEnabled(True) if 'channel' in i.params: self.ui.channel.setValue(i.params["channel"]) if i.params["channel"] == 9: self.ui.channel.setEnabled(False) else: self.ui.channel.setValue(0) if 'note_length' in i.params: self.ui.noteduration.setValue(i.params["note_length"]) if 'min_note_length' not in i.params: self.ui.minnoteduration.setValue(i.params["note_length"]) else: self.ui.noteduration.setValue(1) if 'chance' in i.params: self.ui.chance.setValue(i.params['chance']) self.ui.maxvelocity.setValue(i.params["max_velocity"]) if 'max_velocity' in i.params else self.ui.maxvelocity.setValue(100) self.ui.minvelocity.setValue(i.params["min_velocity"]) if 'min_velocity' in i.params else self.ui.minvelocity.setValue(50) self.ui.minnoteduration.setValue(i.params['min_note_length']) if 'min_note_length' in i.params else self.ui.maxnotes.setValue(1) self.ui.midi.setCurrentIndex(i.params['midi_instr']) if 'midi_instr' in i.params else self.ui.midi.setCurrentIndex(0) self.ui.maxnotes.setValue(i.params['max_notes']) if 'max_notes' in i.params else self.ui.maxnotes.setValue(-1) self.ui.minnote.setCurrentIndex(i.params['min_note']) if 'min_note' in i.params else self.ui.minnote.setCurrentIndex(0) self.ui.maxnote.setCurrentIndex(i.params['max_note']) if 'max_note' in i.params else self.ui.maxnote.setCurrentIndex(115) self.must_play = i.params['must_play'] if 'must_play' in i.params else "" self.must_not_play = i.params['must_not_play'] if 'must_not_play' in i.params else ""
def paint_instruments(self): IOFFSETY = self.IOFFSETY BOXSIZE = self.BOXSIZE # Paint the blocks and progressions # end represents the last bar end = self.paint_prog_block_index() if end is None: return # Paint selector and the current bar. self.paint_selector() self.paint_bar_selector() # Check if instruments need to be repainted instr = self.main.get_instruments() if self.last_instr == instr and end == self.last_end and not self.progchanged: return self.last_instr = instr if instr is not None: old_bars = self.bars bars = {} instr_lst = instr.split(",") instr_parts = [ x.split() for x in instr_lst ] instr_name = [ x[0] for x in instr_parts] for x in self.bar_texts: self.removeItem(x) self.bar_texts = [] for i in range(0, end, 4): t = self.addText(str(i), QtGui.QFont("", 8, 40, True)) t.translate(self.IOFFSETX + i * BOXSIZE, self.IOFFSETY + 9 + len(instr_lst) * self.BOXSIZE) self.bar_texts.append(t) for i, x in enumerate(instr_lst): parts = instr_parts[i] if not old_bars.has_key(x) or end != self.last_end or self.last_instr_names != instr_name: bars[x] = [] # Get instrument name and parameters name = instr_name[i] params = Options.parse_instrument_params(parts[1:]) # Add instrument and midi instrument tooltip s = self.addText(name) if 'midi_instr' in params: s.setToolTip(self.midi_instr.names[params['midi_instr']]) s.translate(0, i * BOXSIZE + IOFFSETY) bars[x].append(s) for n in range(end): plays = self.plays(params, n) if plays > 0: if plays == 1: b = self.brush_play elif plays == 2: b = self.brush_must_play if 'channel' in params and params['channel'] == 9: b = self.brush_percussion if plays == 1 else self.brush_must_play_percussion else: if plays == 0: b = self.brush_dont_play else: b = self.brush_must_not_play a = self.addRect(QtCore.QRectF(self.IOFFSETX + n * BOXSIZE, i * BOXSIZE + IOFFSETY, BOXSIZE - BOXSIZE / 5, BOXSIZE - BOXSIZE / 5 ), self.box_pen,b) bars[x].append(a) else: bars[x] = old_bars[x] del old_bars[x] for x in old_bars: for y in old_bars[x]: self.removeItem(y) self.bars = bars self.last_instr_names = instr_name else: self.center_text("No instruments have been added.") self.last_end = end