Example #1
0
 def on_drag_end(self, event):
   view = self._dragging_connection_view
   self._dragging_connection_view = None
   # remove the view if it didn't form a connection
   view.finalize_connection()
   QApplication.instance().restoreOverrideCursor()
   UndoManager.end_action()
Example #2
0
 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())
Example #3
0
 def on_drag_end(self, event):
   self._start_rect = None
   self._start_bounds = None
   try:
     self._target.on_change()
   except AttributeError: pass
   UndoManager.end_action()
Example #4
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()
Example #5
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)
Example #6
0
 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()
Example #7
0
 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)
Example #8
0
 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()
Example #9
0
 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()
Example #10
0
 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()
Example #11
0
 def detach(self):
   self.document.transport.remove_observer(self.update_actions)
   self.document.view_scale.remove_observer(self.update_actions)
   # remove the document view
   if (self.document_view is not None):
     view = self.document_view
     self.document_view = None
     view.destroy()
     self.stack.removeWidget(view)
   # dump the undo stack and clear the selection
   UndoManager.reset()
Example #12
0
 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
Example #13
0
 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
Example #14
0
 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
Example #15
0
 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()
Example #16
0
 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()
Example #17
0
 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
Example #18
0
 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
Example #19
0
 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)
Example #20
0
 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
Example #21
0
 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
Example #22
0
 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()    
Example #23
0
 def __init__(self, project, objects, readonly=False):
     """
     Args:
         objects: can be one object, or a list of objects
     """
     
     if type(objects) is list:
         self._objects = dict([(obj.uuid, obj) for obj in objects])
         clazz = objects[0].clazz
         attr_type = ATList(clazz.atstruct, unique_attrs=clazz.unique_attrs)
         attr_data = []
         for obj in objects:
             data = copy.deepcopy(obj.raw_data)
             # use this hidden value to locate which object this data belongs to
             data['__uuid__'] = obj.uuid
             attr_data.append(data)
     else:
         self._objects = objects            
         clazz = objects.clazz
         attr_type = clazz.atstruct
         attr_data = copy.deepcopy(objects.raw_data)
     
     self.clazz = clazz
     EditorContext.__init__(self, project, attr_type, attr_data, UndoManager(), readonly)
Example #24
0
 def on_drag_start(self, event):
   UndoManager.begin_action(self._target)
   self._start_pos = self._target.pos()
Example #25
0
 def add_unit(self, new_unit):
   UndoManager.begin_action(self.units)
   self.units.append(new_unit)
   UndoManager.end_action()
Example #26
0
 def on_drag_end_y(self, event):
     self._drag_start_pitches = dict()
     UndoManager.end_action()
Example #27
0
 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()
Example #28
0
 def on_record_stop(self):
     UndoManager.end_action(group='record')
Example #29
0
 def on_drag_end(self, event):
     self.finalize_connection()
     QApplication.instance().restoreOverrideCursor()
     UndoManager.end_action()
Example #30
0
 def on_record_stop(self):
   UndoManager.end_action(group='record')
Example #31
0
 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()
Example #32
0
 def on_drag_end(self, event):
   view.Interactive.on_drag_end(self, event)
   UndoManager.end_action(group='drag_block')
Example #33
0
 def on_drag_start(self, event):
   UndoManager.begin_action(self.block, group='drag_block')
   view.Interactive.on_drag_start(self, event)
Example #34
0
 def on_drag_end(self, event):
   UndoManager.end_action()
Example #35
0
 def on_delete(self, *args):
   UndoManager.begin_action((self.tracks, self.patch_bay))
   self.tracks.remove(self.track)
   UndoManager.end_action()
Example #36
0
 def _make_menus(self):
   menubar = self.menuBar()
   
   # file menu
   file_menu = menubar.addMenu('&File')
   # new
   new_action = QAction(QIcon.fromTheme('document-new'), '&New', self)
   new_action.setShortcut('Ctrl+O')
   new_action.setStatusTip('Open a document')
   new_action.triggered.connect(self.file_new)
   file_menu.addAction(new_action)
   # open
   open_action = QAction(QIcon.fromTheme('document-open'), '&Open', self)
   open_action.setShortcut('Ctrl+O')
   open_action.setStatusTip('Open a document')
   open_action.triggered.connect(self.file_open)
   file_menu.addAction(open_action)
   # save
   save_action = QAction(QIcon.fromTheme('document-save'), '&Save', self)
   save_action.setShortcut('Ctrl+S')
   save_action.setStatusTip('Save the document')
   save_action.triggered.connect(self.file_save)
   file_menu.addAction(save_action)
   # save as
   save_as_action = QAction(QIcon.fromTheme('document-save'), 'Save &As', self)
   save_as_action.setStatusTip('Save the document to a different file')
   save_as_action.triggered.connect(self.file_save_as)
   file_menu.addAction(save_as_action)
   # ---
   file_menu.addSeparator()
   # quit
   quit_action = QAction(QIcon.fromTheme('application-exit'), '&Quit', self)
   quit_action.setShortcut('Ctrl+Q')
   quit_action.setStatusTip('Quit application')
   quit_action.triggered.connect(self.close)
   file_menu.addAction(quit_action)
   
   # edit menu
   edit_menu = menubar.addMenu('&Edit')
   # undo
   self.undo_action = QAction(icon.get('undo'), '&Undo', self)
   self.undo_action.setShortcut('Ctrl+Z')
   self.undo_action.setStatusTip('Undo the last action')
   self.undo_action.triggered.connect(self.edit_undo)
   edit_menu.addAction(self.undo_action)
   # redo
   self.redo_action = QAction(icon.get('redo'), '&Redo', self)
   self.redo_action.setShortcut('Ctrl+Shift+Z')
   self.redo_action.setStatusTip('Redo the last action that was undone')
   self.redo_action.triggered.connect(self.edit_redo)
   edit_menu.addAction(self.redo_action)
   
   # transport menu
   transport_menu = menubar.addMenu('&Transport')
   # go to start
   self.beginning_action = QAction(icon.get('beginning'), 'Jump to &Beginning', self)
   self.beginning_action.setShortcut('Home')
   self.beginning_action.setStatusTip('Jump back to the beginning of the project')
   self.beginning_action.triggered.connect(self.transport_beginning)
   transport_menu.addAction(self.beginning_action)
   # go to end
   self.end_action = QAction(icon.get('ending'), 'Jump to &End', self)
   self.end_action.setShortcut('End')
   self.end_action.setStatusTip('Jump forward to the end of the project')
   self.end_action.triggered.connect(self.transport_end)
   transport_menu.addAction(self.end_action)
   # back
   self.back_action = QAction(icon.get('backward'), 'Bac&k', self)
   self.back_action.setShortcut('PgUp')
   self.back_action.setStatusTip('Skip backward in time')
   self.back_action.triggered.connect(self.transport_back)
   transport_menu.addAction(self.back_action)
   # forward
   self.forward_action = QAction(icon.get('forward'), '&Forward', self)
   self.forward_action.setShortcut('PgDown')
   self.forward_action.setStatusTip('Skip forward in time')
   self.forward_action.triggered.connect(self.transport_forward)
   transport_menu.addAction(self.forward_action)
   # ---
   transport_menu.addSeparator()
   # previous mark
   self.previous_mark_action = QAction(icon.get('mark_previous'), 'Previous Mark', self)
   self.previous_mark_action.setShortcut('Ctrl+PgUp')
   self.previous_mark_action.setStatusTip('Skip to the previous marked time')
   self.previous_mark_action.triggered.connect(self.transport_previous_mark)
   transport_menu.addAction(self.previous_mark_action)
   # toggle mark
   self.toggle_mark_action = QAction(icon.get('mark_toggle'), 'Toggle Mark', self)
   self.toggle_mark_action.setShortcut('Ctrl+\\')
   self.toggle_mark_action.setStatusTip('Toggle a mark at the current time')
   self.toggle_mark_action.triggered.connect(self.transport_toggle_mark)
   transport_menu.addAction(self.toggle_mark_action)
   # next mark
   self.next_mark_action = QAction(icon.get('mark_next'), 'Next Mark', self)
   self.next_mark_action.setShortcut('Ctrl+PgDown')
   self.next_mark_action.setStatusTip('Skip to the next marked time')
   self.next_mark_action.triggered.connect(self.transport_next_mark)
   transport_menu.addAction(self.next_mark_action)
   # cycle
   self.toggle_cycle_action = QAction(icon.get('cycle'), 'Cycle', self)
   self.toggle_cycle_action.setShortcut('Ctrl+L')
   self.toggle_cycle_action.setStatusTip('Toggle cycling playback mode')
   self.toggle_cycle_action.setCheckable(True)
   self.toggle_cycle_action.toggled.connect(self.transport_toggle_cycle)
   transport_menu.addAction(self.toggle_cycle_action)
   # ---
   transport_menu.addSeparator()
   # stop
   self.stop_action = QAction(icon.get('stop'), '&Stop', self)
   self.stop_action.setStatusTip('Stop playback or recording')
   self.stop_action.triggered.connect(self.transport_stop)
   transport_menu.addAction(self.stop_action)
   # play
   self.play_action = QAction(icon.get('play'), '&Play', self)
   self.play_action.setStatusTip('Start playback')
   self.play_action.triggered.connect(self.transport_play)
   transport_menu.addAction(self.play_action)
   # record
   self.record_action = QAction(icon.get('record'), '&Record', self)
   self.record_action.setStatusTip('Start recording')
   self.record_action.triggered.connect(self.transport_record)
   transport_menu.addAction(self.record_action)
   # ---
   transport_menu.addSeparator()
   # zoom in
   self.zoom_in_action = QAction(icon.get('zoom_in'), 'Zoom &In', self)
   self.zoom_in_action.setShortcut('Ctrl+Shift+Plus')
   self.zoom_in_action.setStatusTip('Zoom in')
   self.zoom_in_action.triggered.connect(self.transport_zoom_in)
   transport_menu.addAction(self.zoom_in_action)
   # zoom out
   self.zoom_out_action = QAction(icon.get('zoom_out'), 'Zoom &Out', self)
   self.zoom_out_action.setShortcut('Ctrl+Shift+Minus')
   self.zoom_out_action.setStatusTip('Zoom out')
   self.zoom_out_action.triggered.connect(self.transport_zoom_out)
   transport_menu.addAction(self.zoom_out_action)
   
   # toolbar
   self.toolbar = self.addToolBar('Main')
   self.toolbar.addAction(self.undo_action)
   self.toolbar.addAction(self.redo_action)
   self.toolbar.addSeparator()
   self.toolbar.addAction(self.beginning_action)
   self.toolbar.addAction(self.back_action)
   self.toolbar.addAction(self.forward_action)
   self.toolbar.addAction(self.end_action)
   self.toolbar.addSeparator()
   self.toolbar.addAction(self.stop_action)
   self.toolbar.addAction(self.play_action)
   self.toolbar.addAction(self.record_action)
   self.toolbar.addSeparator()
   self.toolbar.addAction(self.zoom_out_action)
   self.toolbar.addAction(self.zoom_in_action)
   # give actions their initial states
   UndoManager.add_observer(self.update_actions)
   self.update_actions()
Example #37
0
 def on_drag_end(self, event):
   self.finalize_connection()
   QApplication.instance().restoreOverrideCursor()
   UndoManager.end_action()
Example #38
0
 def on_record_start(self):
   UndoManager.begin_action(self.unit.tracks, group='record')
Example #39
0
 def edit_redo(self):
   UndoManager.redo()
Example #40
0
 def on_add(self):
   UndoManager.begin_action(self.unit.tracks)
   self.unit.tracks.add_track()
   UndoManager.end_action()
Example #41
0
 def focusInEvent(self, e):
     UndoManager.begin_action(self._model)
     EditableLabel.focusInEvent(self, e)
Example #42
0
 def on_record_start(self):
     UndoManager.begin_action(self.unit.tracks, group='record')
Example #43
0
 def on_drag_start(self, event):
     UndoManager.begin_action(self._target)
     self._start_pos = self._target.pos()
Example #44
0
 def on_add(self):
     UndoManager.begin_action(self.unit.tracks)
     self.unit.tracks.add_track()
     UndoManager.end_action()
Example #45
0
 def on_change_path(self, path):
   UndoManager.begin_action(self.instrument)
   self.instrument.path = path
   UndoManager.end_action()
Example #46
0
 def edit_undo(self):
   UndoManager.undo()
Example #47
0
 def on_drag_end_x(self, event):
     self._drag_start_times = dict()
     UndoManager.end_action()
Example #48
0
 def on_browse(self):
   UndoManager.begin_action(self.instrument)
   self.instrument.browse()
   UndoManager.end_action()
Example #49
0
 def focusOutEvent(self, e):
     EditableLabel.focusOutEvent(self, e)
     UndoManager.end_action()
Example #50
0
 def on_drag_start(self, event):
   UndoManager.begin_action(self.events)
Example #51
0
 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()