Sweep [Home] [Tutorials] Hosted at SourceForge

Developing Sweep Plugins

PreviousContentsNext

Using native plugins

Sweep maintains a stack of recent operations for each sample, which are used to allow undoing and redoing of all operations. If you write a new operation method that modifies a sample's 'sounddata' (ie. the sampling rate, length, selections or audio data) then you must implement Undo and Redo methods for it. However if you are using one of the convenience mechanisms covered in Sections 2.7 and 2.8 then these things are already taken care of by the perform_* functions.

Once an operation has been successfully performed, it needs to register itself with Sweep's undo handler. This involves:

  1. Finding or constructing an sw_operation structure. These are often statically defined.
  2. Creating an sw_op_instance structure. This contains a description of the operation performed, a pointer to the sw_operation, and pointers to data for use in undoing and redoing the operation performed.
  3. Calling register_operation() to add the sw_op_instance to the sample's stack of operations.

The apply() method of a proc usually does these things, does its actual work, registers the operation then returns the sw_op_instance created.

An operation given by (sw_op_instance * inst) is undone by calling

inst->op->undo (sample, inst->undo_data);

and redone by calling

inst->op->redo (sample, inst->redo_data);

When an operation instance can be discarded (eg. if only a finite number of recent operations are remembered), the undo_data and redo_data members are purged by calling

inst->op->purge_undo (inst->undo_data); inst->op->purge_redo (inst->redo_data);

Thus, if any memory was allocated to create undo_data or redo_data it should be freed in the purge functions.

Some stock undo and redo methods exist for handling operations which need to paste new data over the selected region, or which need to splice data into the sample. These are outlined in . For examples of their use, see "src/edit.c" in the Sweep application source.

PreviousContentsNext

Copyright © 2000 Conrad Parker.