def select_box(self, event, r): UndoManager.begin_action(end_timeout=500) modifiers = event.modifiers() if ((modifiers != Qt.ShiftModifier) and (modifiers != Qt.ControlModifier)): Selection.deselect_all() self._select_children_in_box(self, r, modifiers, set())
def on_split(self, *args): current_track = None for track in self.tracks: if (self.block in track): current_track = track break # if the block has multiple repeats, split the repeats if (self.block.events.duration < self.block.duration): UndoManager.begin_action(track) self.block.split_repeats(track=current_track) UndoManager.end_action() else: times = [ ] # get selected events in the block selected_events = self.get_selected_notes() # if events are selected in the block, find boundaries # between selected and deselected events if (len(selected_events) > 0): # sort all block events by time events = list(self.block.events) events.sort(key=lambda e: e.time) # find boundaries was_selected = (events[0] in selected_events) for event in events: # count notes only if (not hasattr(event, 'pitch')): continue is_selected = (event in selected_events) if (is_selected != was_selected): times.append(event.time) was_selected = is_selected # if there are times to split on, we can split if (len(times) > 0): UndoManager.begin_action((self.block, current_track)) self.block.split(times, track=current_track) UndoManager.end_action()
def select_box(self, event, r): UndoManager.begin_action(end_timeout=500) modifiers = event.modifiers() if ((modifiers != Qt.ShiftModifier) and (modifiers != Qt.ControlModifier)): Selection.deselect_all() self._select_children_in_box(self, r, modifiers, set())
def on_drag_start(self, event): UndoManager.begin_action(self._target) self._start_rect = self._target.rect() self._start_bounds = self._target.boundingRect().normalized() if (self._start_bounds.width() == 0): self._start_bounds.setWidth(1.0) if (self._start_bounds.height() == 0): self._start_bounds.setHeight(1.0)
def on_drag_start(self, event): UndoManager.begin_action(self._target) self._start_rect = self._target.rect() self._start_bounds = self._target.boundingRect().normalized() if (self._start_bounds.width() == 0): self._start_bounds.setWidth(1.0) if (self._start_bounds.height() == 0): self._start_bounds.setHeight(1.0)
def on_group(self): workspace_view = self.view.parentItemWithAttribute('document') if (workspace_view is None): return units = workspace_view.document.units selected_units = self.selected_units() UndoManager.begin_action(units) units.append(GroupUnit(units=selected_units, name='Group')) UndoManager.end_action()
def on_join(self, *args): blocks = self.get_selected_blocks() blocks.add(self.block) UndoManager.begin_action((blocks, self.tracks)) if (len(blocks) > 1): self.block.join(blocks, tracks=self.tracks) else: self.block.join_repeats() UndoManager.end_action()
def on_drag_start(self, event): UndoManager.begin_action((self.connection, self.patch_bay)) pos = event.pos() source = self._source_pos sink = self._sink_pos source_dist = abs(pos.x() - source.x()) + abs(pos.y() - source.y()) sink_dist = abs(pos.x() - sink.x()) + abs(pos.y() - sink.y()) self._drag_sink = (sink_dist < source_dist) QApplication.instance().setOverrideCursor(Qt.ClosedHandCursor)
def on_drag_start(self, event): UndoManager.begin_action((self.connection, self.patch_bay)) pos = event.pos() source = self._source_pos sink = self._sink_pos source_dist = abs(pos.x() - source.x()) + abs(pos.y() - source.y()) sink_dist = abs(pos.x() - sink.x()) + abs(pos.y() - sink.y()) self._drag_sink = (sink_dist < source_dist) QApplication.instance().setOverrideCursor(Qt.ClosedHandCursor)
def on_delete(self, *args): current_track = None for track in self.tracks: if (self.block in track): current_track = track break if (current_track is None): return UndoManager.begin_action(current_track) current_track.remove(self.block) UndoManager.end_action()
def on_key_delete(self, event): root_item = self while root_item.parentItem(): root_item = root_item.parentItem() document_view = self.parentItemWithAttribute('document') document = None if (document_view is not None): document = document_view.document UndoManager.begin_action(document) self._delete_selected_child_items(root_item) UndoManager.end_action()
def toggle_mark(self, *args): UndoManager.begin_action(self.marks) t = self.time found = False for mark in set(self.marks): if (mark.time == t): self.marks.remove(mark) found = True if (not found): self.marks.append(Mark(time=t)) UndoManager.end_action()
def on_key_delete(self, event): root_item = self while root_item.parentItem(): root_item = root_item.parentItem() document_view = self.parentItemWithAttribute('document') document = None if (document_view is not None): document = document_view.document UndoManager.begin_action(document) self._delete_selected_child_items(root_item) UndoManager.end_action()
def on_key_y(self, event): UndoManager.begin_action(end_timeout=500) # get the time difference equivalent to one pixel delta_pitch = 1 if (event.key() == Qt.Key_Down): delta_pitch *= -1 # make a bigger jump when the shift key is down if (event.modifiers() == Qt.ShiftModifier): delta_pitch *= 12 # apply to the selection for model in Selection.models: model.pitch += delta_pitch
def on_key_x(self, event): UndoManager.begin_action(end_timeout=500) # get the time difference equivalent to one pixel delta_time = self.mapFromScene(1, 0).x() - self.mapFromScene(0, 0).x() if (event.key() == Qt.Key_Left): delta_time *= -1 # make a bigger jump when the shift key is down if (event.modifiers() == Qt.ShiftModifier): delta_time = self._get_time_jump(delta_time) # apply to the selection for model in Selection.models: model.time += delta_time
def on_key_x(self, event): UndoManager.begin_action(end_timeout=500) # get the time difference equivalent to one pixel delta_time = self.mapFromScene(1, 0).x() - self.mapFromScene(0, 0).x() if (event.key() == Qt.Key_Left): delta_time *= -1 # make a bigger jump when the shift key is down if (event.modifiers() == Qt.ShiftModifier): delta_time = self._get_time_jump(delta_time) # apply to the selection for model in Selection.models: model.time += delta_time
def on_key_y(self, event): UndoManager.begin_action(end_timeout=500) # get the time difference equivalent to one pixel delta_pitch = 1 if (event.key() == Qt.Key_Down): delta_pitch *= -1 # make a bigger jump when the shift key is down if (event.modifiers() == Qt.ShiftModifier): delta_pitch *= 12 # apply to the selection for model in Selection.models: model.pitch += delta_pitch
def on_drag_start_y(self, event): UndoManager.begin_action() # select the model if it isn't selected if (not self.model.selected): Selection.deselect_all() self.model.selected = True # record the original pitches of all selected models self._drag_start_pitches = dict() for model in Selection.models: try: self._drag_start_pitches[model] = model.pitch except AttributeError: continue
def on_drag_start_y(self, event): UndoManager.begin_action() # select the model if it isn't selected if (not self.model.selected): Selection.deselect_all() self.model.selected = True # record the original pitches of all selected models self._drag_start_pitches = dict() for model in Selection.models: try: self._drag_start_pitches[model] = model.pitch except AttributeError: continue
def remove_unit(self, unit, inputs=(), outputs=()): units = self.units patch_bay = self.patch_bay UndoManager.begin_action((units, patch_bay, inputs, outputs)) patch_bay.remove_connections_for_unit(unit) for item in inputs: patch_bay.remove_connections_for_unit(item) for item in outputs: patch_bay.remove_connections_for_unit(item) units.remove(unit) # remove the unit from any groups it might be a part of for group in units: if ((hasattr(group, 'units')) and (unit in group.units)): group.units.remove(unit) UndoManager.end_action()
def on_click(self, event): UndoManager.begin_action(end_timeout=500) if ((self.allow_multiselect) and (event.modifiers() == Qt.ShiftModifier)): self.model.selected = True elif ((self.allow_multiselect) and (event.modifiers() == Qt.ControlModifier)): self.model.selected = not self.model.selected else: try: if (self.model.selected): event.ignore() return except AttributeError: pass Selection.deselect_all() self.model.selected = True
def on_drag_start_x(self, event): UndoManager.begin_action() # select the model if it isn't selected can_select = hasattr(self.model, 'selected') if ((not can_select) or (not self.model.selected)): Selection.deselect_all() if (can_select): self.model.selected = True # record the original times of all selected models self._drag_start_times = dict() models = set(Selection.models) models.add(self.model) for model in models: try: self._drag_start_times[model] = model.time except AttributeError: continue
def on_drag_start(self, event): UndoManager.begin_action(self.patch_bay) # make a connection and add it to the workspace connection = unit.Connection() view = ConnectionView(connection) if (isinstance(self, UnitOutputView)): view.source_view = self else: view.sink_view = self workspace_view = self.parentItemWithAttribute('connection_layer') if (workspace_view): view.setParentItem(workspace_view.connection_layer) else: view.setParentItem(self) self._dragging_connection_view = view QApplication.instance().setOverrideCursor(Qt.ClosedHandCursor)
def on_drag_start(self, event): UndoManager.begin_action(self.patch_bay) # make a connection and add it to the workspace connection = unit.Connection() view = ConnectionView(connection) if (isinstance(self, UnitOutputView)): view.source_view = self else: view.sink_view = self workspace_view = self.parentItemWithAttribute('connection_layer') if (workspace_view): view.setParentItem(workspace_view.connection_layer) else: view.setParentItem(self) self._dragging_connection_view = view QApplication.instance().setOverrideCursor(Qt.ClosedHandCursor)
def on_drag_start_x(self, event): UndoManager.begin_action() # select the model if it isn't selected can_select = hasattr(self.model, 'selected') if ((not can_select) or (not self.model.selected)): Selection.deselect_all() if (can_select): self.model.selected = True # record the original times of all selected models self._drag_start_times = dict() models = set(Selection.models) models.add(self.model) for model in models: try: self._drag_start_times[model] = model.time except AttributeError: continue
def on_click(self, event): UndoManager.begin_action(end_timeout=500) if ((self.allow_multiselect) and (event.modifiers() == Qt.ShiftModifier)): self.model.selected = True elif ((self.allow_multiselect) and (event.modifiers() == Qt.ControlModifier)): self.model.selected = not self.model.selected else: try: if (self.model.selected): event.ignore() return except AttributeError: pass Selection.deselect_all() self.model.selected = True
def change_track(self, delta): block = self.block # get the track list and track that contain this block tracks_view = self.parentItemWithAttribute('tracks') track_view = self.parentItemWithAttribute('track') if ((tracks_view is None) or (track_view is None)): return tracks = tracks_view.tracks current_track = track_view.track if (len(tracks) <= 1): return # get the index of the current track current_index = tracks.index(current_track) # get the new track index, and exit if it's not changing new_index = min(max(0, current_index + delta), len(tracks) - 1) if (new_index == current_index): return new_track = tracks[new_index] UndoManager.begin_action((current_track, new_track)) # move this view into the new track layout so # it maintains its keyboard/mouse focus old_layout = self.parentItem() def find_track_layout(node, track): for item in node.childItems(): if ((isinstance(item, view.ListLayout)) and (hasattr(item, 'track')) and (item.track is track)): return(item) result = find_track_layout(item, track) if (result is not None): return(result) return(None) new_layout = find_track_layout(tracks_view.track_layout, new_track) del old_layout._view_map[block] new_layout._view_map[block] = self self.setParentItem(new_layout) # move the block in the model layer current_track.remove(block) new_track.append(block) UndoManager.end_action()
def on_browse(self): UndoManager.begin_action(self.instrument) self.instrument.browse() UndoManager.end_action()
def add_unit(self, new_unit): UndoManager.begin_action(self.units) self.units.append(new_unit) UndoManager.end_action()
def on_add(self): UndoManager.begin_action(self.unit.tracks) self.unit.tracks.add_track() UndoManager.end_action()
def on_record_start(self): UndoManager.begin_action(self.unit.tracks, group='record')
def on_drag_start(self, event): UndoManager.begin_action(self._target) self._start_pos = self._target.pos()
def on_change_path(self, path): UndoManager.begin_action(self.instrument) self.instrument.path = path UndoManager.end_action()
def on_add(self): instrument = sampler.Instrument.new_from_browse() if (instrument is None): return UndoManager.begin_action(self._content.instruments) self._content.instruments.append(instrument) UndoManager.end_action()
def on_record_start(self): UndoManager.begin_action(self.unit.tracks, group='record')
def on_remove(self): UndoManager.begin_action((self.instruments, self.document)) if (self.document is not None): self.document.patch_bay.remove_connections_for_unit(self.instrument) self.instruments.remove(self.instrument) UndoManager.end_action()
def on_drag_start(self, event): UndoManager.begin_action(self.block, group='drag_block') view.Interactive.on_drag_start(self, event)
def on_drag_start(self, event): UndoManager.begin_action(self.events)
def focusInEvent(self, e): UndoManager.begin_action(self._model) EditableLabel.focusInEvent(self, e)
def on_delete(self, *args): UndoManager.begin_action((self.tracks, self.patch_bay)) self.tracks.remove(self.track) UndoManager.end_action()
def on_add(self): UndoManager.begin_action(self.unit.tracks) self.unit.tracks.add_track() UndoManager.end_action()
def on_drag_start(self, event): UndoManager.begin_action(self._target) self._start_pos = self._target.pos()
def on_add(self): instrument = sampler.Instrument.new_from_browse() if (instrument is None): return UndoManager.begin_action(self._content.instruments) self._content.instruments.append(instrument) UndoManager.end_action()
def focusInEvent(self, e): UndoManager.begin_action(self._model) EditableLabel.focusInEvent(self, e)