Karya, built on 2018-03-16T03:22:32 (patch df7306861219887e676081746f4a4edfe05eb0b5)

Safe HaskellNone



Implement a clipboard, and copy and paste from a selection.

Who knew copy and paste was so complicated? Copying is complicated because the structure isn't flat, i.e. a block has references to tracks and rulers. Pasting is complicated because the clipboard events have to be shifted and clipped according to the destination selection.

Also, the tracks are typed in that it's not appropriate to paste control events into a note track. However, I'm going to ignore that and assume the user won't paste them if he didn't mean it.

Instead of having a special case clipboard, the clipboard is implemented as a normal block and tracks (rulers are not copied), in a clipboard namespace. That way, you can have multiple clipboards by copying them to different clipboard namespaces, edit clipboards in place, and the paste code is the same as the code that merges another project from disk.

Further ideas:

  • use two selections and a "swap" command
  • mouse chording for copy paste
  • different mouse buttons are hard to do on the mac, so use standard for now
  • merge with function... I think I can just do it at the REPL

More complicated pastes should be implemented as derivers, which are more flexible than editing operations. However, there could be a "derive in place" cmd to flatten deriver structure.



state_to_clip :: Cmd.M m => Ui.State -> m () Source #

Replace the clipboard with the given state. This can be used to load another score and use the clipboard as a staging area.

clear_clip :: Cmd.M m => m () Source #

cmd_cut_selection :: Cmd.M m => m () Source #

Like cmd_copy_selection, but clear the selection after copying it.

cmd_copy_selection :: Cmd.M m => m () Source #

Copy events under the current selection into the buffer.

cmd_paste_overwrite :: Cmd.M m => m () Source #

The normal variety of paste that replaces the destination data.

cmd_paste_soft_merge :: Cmd.M m => m () Source #

Like cmd_paste_merge, except don't merge events that overlap with existing ones.

cmd_paste_insert :: Cmd.M m => m () Source #

Insert the events after pushing events after the selection down by the inserted length, which is the minimum of the insert selection and the length of the buffer.

cmd_paste_stretch :: Cmd.M m => m () Source #

Paste the clipboard, but stretch or compress it to fit the selection.

state_to_namespace :: Ui.M m => Ui.State -> Id.Namespace -> m () Source #

Rename the blocks and tracks in the given state into the given namespace and replace the IDs already in that namespace with it. Rulers are ignored.

This means that if the given state has IDs in more than one namespace, they will be flattened into one. Any collisions will throw an exception.