Document Class Reference

#include <Document.h>

Inherits XmlExportable.

Inheritance diagram for Document:

Inheritance graph
[legend]
Collaboration diagram for Document:

Collaboration graph
[legend]
List of all members.

Detailed Description

A Sonic Visualiser document consists of a set of data models, and also the visualisation layers used to display them.

Changes to the layers and their layout need to be stored and managed in much the same way as changes to the underlying data.

The document manages:

The document does *not* manage the existence or structure of Pane and other view widgets. However, it does provide convenience methods for reference-counted command-based management of the association between layers and views (addLayerToView, removeLayerFromView).

Definition at line 65 of file Document.h.

Signals

void layerAdded (Layer *)
void layerRemoved (Layer *)
void layerAboutToBeDeleted (Layer *)
void layerInAView (Layer *, bool)
void modelAdded (Model *)
void mainModelChanged (WaveFileModel *)
void modelAboutToBeDeleted (Model *)
void modelGenerationFailed (QString transformName, QString message)
void modelGenerationWarning (QString transformName, QString message)
void modelRegenerationFailed (QString layerName, QString transformName, QString message)
void modelRegenerationWarning (QString layerName, QString transformName, QString message)
void alignmentFailed (QString transformName, QString message)

Public Member Functions

 Document ()
 !! still need to handle command history, documentRestored/documentModified
virtual ~Document ()
LayercreateLayer (LayerFactory::LayerType)
 Create and return a new layer of the given type, associated with no model.
LayercreateMainModelLayer (LayerFactory::LayerType)
 Create and return a new layer of the given type, associated with the current main model (if appropriate to the layer type).
LayercreateImportedLayer (Model *)
 Create and return a new layer associated with the given model, and register the model as an imported model.
LayercreateEmptyLayer (LayerFactory::LayerType)
 Create and return a new layer of the given type, with an appropriate empty model.
LayercreateDerivedLayer (LayerFactory::LayerType, TransformId)
 Create and return a new layer of the given type, associated with the given transform name.
LayercreateDerivedLayer (const Transform &, const ModelTransformer::Input &)
 Create and return a suitable layer for the given transform, running the transform and associating the resulting model with the new layer.
void deleteLayer (Layer *, bool force=false)
 Delete the given layer, and also its associated model if no longer used by any other layer.
void setMainModel (WaveFileModel *)
 Set the main model (the source for playback sample rate, etc) to the given wave file model.
WaveFileModelgetMainModel ()
 Get the main model (the source for playback sample rate, etc).
const WaveFileModelgetMainModel () const
 Get the main model (the source for playback sample rate, etc).
std::vector< Model * > getTransformInputModels ()
bool isKnownModel (const Model *) const
ModeladdDerivedModel (const Transform &transform, const ModelTransformer::Input &input, QString &returnedMessage)
 Add a derived model associated with the given transform, running the transform and returning the resulting model.
void addDerivedModel (const Transform &transform, const ModelTransformer::Input &input, Model *outputModelToAdd)
 Add a derived model associated with the given transform.
void addImportedModel (Model *)
 Add an imported (non-derived, non-main) model.
void setModel (Layer *, Model *)
 Associate the given model with the given layer.
void setChannel (Layer *, int)
 Set the given layer to use the given channel of its model (-1 means all available channels).
void addLayerToView (View *, Layer *)
 Add the given layer to the given view.
void removeLayerFromView (View *, Layer *)
 Remove the given layer from the given view.
void setAutoAlignment (bool on)
 Specify whether models added via addImportedModel should be automatically aligned against the main model if appropriate.
void alignModels ()
 Generate alignments for all appropriate models against the main model.
void toXml (QTextStream &, QString indent, QString extraAttributes) const
 Stream this exportable object out to XML on a text stream.
virtual QString toXmlString (QString indent="", QString extraAttributes="") const
 Convert this exportable object to XML in a string.

Static Public Member Functions

static bool canAlign ()
 Return true if alignment is supported (i.e.
static QString encodeEntities (QString)
static QString encodeColour (QColor)
static int getObjectExportId (const void *)

Protected Types

typedef std::map< Model *,
ModelRecord
ModelMap
typedef std::map< Layer *,
std::set< View * > > 
LayerViewMap
typedef std::set< Layer * > LayerSet
 And these are the layers.

Protected Member Functions

void releaseModel (Model *model)
void alignModel (Model *)
 If model is suitable for alignment, align it against the main model and store the alignment in the model.
void addToLayerViewMap (Layer *, View *)
void removeFromLayerViewMap (Layer *, View *)
QString getUniqueLayerName (QString candidate)
void writeBackwardCompatibleDerivation (QTextStream &, QString, Model *, const ModelRecord &) const

Static Protected Member Functions

static TransformId getAlignmentTransformName ()

Protected Attributes

WaveFileModelm_mainModel
 The model that provides the underlying sample rate, etc.
ModelMap m_models
LayerViewMap m_layerViewMap
LayerSet m_layers
bool m_autoAlignment

Classes

class  AddLayerCommand
struct  ModelRecord
class  RemoveLayerCommand


Member Typedef Documentation

typedef std::map<Model *, ModelRecord> Document::ModelMap [protected]

Definition at line 284 of file Document.h.

typedef std::map<Layer *, std::set<View *> > Document::LayerViewMap [protected]

Definition at line 323 of file Document.h.

typedef std::set<Layer *> Document::LayerSet [protected]

And these are the layers.

We also control the lifespans of these (usually through the commands used to add and remove them).

Definition at line 339 of file Document.h.


Constructor & Destructor Documentation

Document::Document (  ) 

!! still need to handle command history, documentRestored/documentModified

Definition at line 44 of file Document.cpp.

References ModelTransformerFactory::getInstance(), and modelAboutToBeDeleted().

Document::~Document (  )  [virtual]

Definition at line 53 of file Document.cpp.

References Model::aboutToDelete(), CommandHistory::clear(), deleteLayer(), CommandHistory::getInstance(), m_layers, m_mainModel, m_models, mainModelChanged(), and modelAboutToBeDeleted().


Member Function Documentation

Layer * Document::createLayer ( LayerFactory::LayerType   ) 

Create and return a new layer of the given type, associated with no model.

The caller may set any model on this layer, but the model must also be registered with the document via the add-model methods below.

Definition at line 106 of file Document.cpp.

References LayerFactory::createLayer(), LayerFactory::getInstance(), getUniqueLayerName(), layerAdded(), m_layers, and Layer::setObjectName().

Referenced by MainWindow::addLayer(), MainWindow::addPane(), createDerivedLayer(), createEmptyLayer(), createMainModelLayer(), and SVFileReader::readLayer().

Layer * Document::createMainModelLayer ( LayerFactory::LayerType   ) 

Create and return a new layer of the given type, associated with the current main model (if appropriate to the layer type).

Definition at line 126 of file Document.cpp.

References createLayer(), m_mainModel, and setModel().

Referenced by MainWindow::addLayer(), MainWindow::addPane(), and MainWindow::newSession().

Layer * Document::createImportedLayer ( Model  ) 

Create and return a new layer associated with the given model, and register the model as an imported model.

!! for now, just use the first suitable layer type

!! and all channels

Definition at line 135 of file Document.cpp.

References addImportedModel(), LayerFactory::createLayer(), LayerFactory::getInstance(), getUniqueLayerName(), LayerFactory::getValidLayerTypes(), layerAdded(), m_layers, setChannel(), setModel(), and Layer::setObjectName().

Referenced by MainWindowBase::openAudio(), and MainWindowBase::openLayer().

Layer * Document::createEmptyLayer ( LayerFactory::LayerType   ) 

Create and return a new layer of the given type, with an appropriate empty model.

If the given type is not one for which an empty model can meaningfully be created, return 0.

Definition at line 171 of file Document.cpp.

References addImportedModel(), LayerFactory::createEmptyModel(), createLayer(), LayerFactory::getInstance(), m_mainModel, and setModel().

Referenced by MainWindow::addLayer(), MainWindowBase::insertInstantAt(), MainWindowBase::openImage(), and MainWindowBase::paste().

Layer * Document::createDerivedLayer ( LayerFactory::LayerType  ,
TransformId   
)

Create and return a new layer of the given type, associated with the given transform name.

This method does not run the transform itself, nor create a model. The caller can safely add a model to the layer later, but note that all models used by a transform layer _must_ be registered with the document using addDerivedModel below.

Definition at line 192 of file Document.cpp.

References createLayer(), TransformFactory::getInstance(), getUniqueLayerName(), and Layer::setObjectName().

Referenced by MainWindow::addLayer(), and MainWindow::handleOSCMessage().

Layer * Document::createDerivedLayer ( const Transform ,
const ModelTransformer::Input  
)

Create and return a suitable layer for the given transform, running the transform and associating the resulting model with the new layer.

!! for now, just use the first suitable layer type

!! We need to clone the model when adding the layer, so that it

Definition at line 206 of file Document.cpp.

References addDerivedModel(), createLayer(), Transform::getIdentifier(), TransformFactory::getInstance(), LayerFactory::getInstance(), getUniqueLayerName(), LayerFactory::getValidLayerTypes(), layerAdded(), modelGenerationFailed(), modelGenerationWarning(), setModel(), and Layer::setObjectName().

void Document::deleteLayer ( Layer ,
bool  force = false 
)

Delete the given layer, and also its associated model if no longer used by any other layer.

In general, this should be the only method used to delete layers -- doing so directly is a bit of a social gaffe.

Definition at line 545 of file Document.cpp.

References Layer::getModel(), layerAboutToBeDeleted(), layerRemoved(), m_layers, m_layerViewMap, and releaseModel().

Referenced by MainWindowBase::openImage(), setMainModel(), Document::AddLayerCommand::~AddLayerCommand(), ~Document(), and Document::RemoveLayerCommand::~RemoveLayerCommand().

void Document::setMainModel ( WaveFileModel  ) 

Set the main model (the source for playback sample rate, etc) to the given wave file model.

This will regenerate any derived models that were based on the previous main model.

!! We have a problem here if the number of channels in

Definition at line 259 of file Document.cpp.

References Model::aboutToDelete(), addDerivedModel(), alignModel(), deleteLayer(), DenseTimeValueModel::getChannelCount(), Transform::getIdentifier(), LayerFactory::getInstance(), m_autoAlignment, m_layers, m_mainModel, m_models, mainModelChanged(), modelAboutToBeDeleted(), modelAdded(), modelRegenerationFailed(), modelRegenerationWarning(), setModel(), and LayerFactory::setModel().

Referenced by MainWindowBase::openAudio(), and SVFileReader::readModel().

WaveFileModel* Document::getMainModel (  )  [inline]

Get the main model (the source for playback sample rate, etc).

Definition at line 137 of file Document.h.

References m_mainModel.

Referenced by MainWindow::addPane(), MainWindowBase::getMainModel(), MainWindowBase::openImage(), and SVFileReader::readDerivation().

const WaveFileModel* Document::getMainModel (  )  const [inline]

Get the main model (the source for playback sample rate, etc).

Definition at line 142 of file Document.h.

References m_mainModel.

std::vector< Model * > Document::getTransformInputModels (  ) 

Definition at line 732 of file Document.cpp.

References m_mainModel, and m_models.

Referenced by MainWindow::addLayer(), MainWindow::addPane(), and MainWindow::setupPaneAndLayerMenus().

bool Document::isKnownModel ( const Model  )  const

Definition at line 757 of file Document.cpp.

References m_mainModel, and m_models.

Referenced by MainWindow::addLayer().

Model * Document::addDerivedModel ( const Transform transform,
const ModelTransformer::Input input,
QString &  returnedMessage 
)

Add a derived model associated with the given transform, running the transform and returning the resulting model.

Definition at line 450 of file Document.cpp.

References ModelTransformer::Input::getChannel(), Transform::getIdentifier(), TransformFactory::getInstance(), ModelTransformerFactory::getInstance(), ModelTransformer::Input::getModel(), Transform::getSampleRate(), m_models, Transform::setPluginVersion(), and ModelTransformerFactory::transform().

Referenced by createDerivedLayer(), SVFileReader::endElement(), and setMainModel().

void Document::addDerivedModel ( const Transform transform,
const ModelTransformer::Input input,
Model outputModelToAdd 
)

Add a derived model associated with the given transform.

This is necessary to register any derived model that was not created by the document using createDerivedModel or createDerivedLayer.

Definition at line 401 of file Document.cpp.

References Document::ModelRecord::channel, ModelTransformer::Input::getChannel(), ModelTransformer::Input::getModel(), m_models, modelAdded(), Document::ModelRecord::refcount, Model::setSourceModel(), Document::ModelRecord::source, and Document::ModelRecord::transform.

void Document::addImportedModel ( Model  ) 

Add an imported (non-derived, non-main) model.

This is necessary to register any imported model that is associated with a layer.

Definition at line 430 of file Document.cpp.

References alignModel(), m_autoAlignment, m_models, modelAdded(), Document::ModelRecord::refcount, and Document::ModelRecord::source.

Referenced by SVFileReader::addUnaddedModels(), createEmptyLayer(), createImportedLayer(), and MainWindowBase::openAudio().

void Document::setModel ( Layer ,
Model  
)

Associate the given model with the given layer.

The model must have already been registered using one of the addXXModel methods above.

Definition at line 594 of file Document.cpp.

References PlayParameterRepository::copyParameters(), LayerFactory::getInstance(), PlayParameterRepository::getInstance(), Layer::getModel(), m_mainModel, m_models, releaseModel(), and LayerFactory::setModel().

Referenced by MainWindow::addLayer(), MainWindow::addPane(), createDerivedLayer(), createEmptyLayer(), createImportedLayer(), createMainModelLayer(), SVFileReader::readLayer(), and setMainModel().

void Document::setChannel ( Layer ,
int   
)

Set the given layer to use the given channel of its model (-1 means all available channels).

Definition at line 636 of file Document.cpp.

References LayerFactory::getInstance(), and LayerFactory::setChannel().

Referenced by MainWindow::addLayer(), MainWindow::addPane(), and createImportedLayer().

void Document::addLayerToView ( View ,
Layer  
)

Add the given layer to the given view.

If the layer is intended to show a particular model, the model should normally be set using setModel before this method is called.

Definition at line 642 of file Document.cpp.

References CommandHistory::addCommand(), CommandHistory::getInstance(), Layer::getModel(), m_mainModel, and m_models.

Referenced by MainWindow::addLayer(), MainWindow::addPane(), MainWindow::handleOSCMessage(), MainWindowBase::insertInstantAt(), MainWindow::newSession(), MainWindowBase::openAudio(), MainWindowBase::openImage(), MainWindowBase::openLayer(), MainWindowBase::paste(), and SVFileReader::readLayer().

void Document::removeLayerFromView ( View ,
Layer  
)

Remove the given layer from the given view.

Definition at line 667 of file Document.cpp.

References CommandHistory::addCommand(), and CommandHistory::getInstance().

Referenced by MainWindow::closeSession(), MainWindowBase::deleteCurrentLayer(), MainWindowBase::deleteCurrentPane(), MainWindowBase::openAudio(), and MainWindowBase::paneDeleteButtonClicked().

bool Document::canAlign (  )  [static]

Return true if alignment is supported (i.e.

if the necessary plugin is found).

Definition at line 776 of file Document.cpp.

References getAlignmentTransformName(), TransformFactory::getInstance(), and TransformFactory::haveTransform().

Referenced by MainWindow::setupToolbars(), and MainWindow::updateMenuStates().

void Document::setAutoAlignment ( bool  on  )  [inline]

Specify whether models added via addImportedModel should be automatically aligned against the main model if appropriate.

Definition at line 207 of file Document.h.

References m_autoAlignment.

Referenced by MainWindow::alignToggled().

void Document::alignModels (  ) 

Generate alignments for all appropriate models against the main model.

Existing alignments will not be re-calculated unless the main model has changed since they were calculated.

Definition at line 876 of file Document.cpp.

References alignModel(), m_mainModel, and m_models.

Referenced by MainWindow::alignToggled().

void Document::toXml ( QTextStream &  ,
QString  indent,
QString  extraAttributes 
) const [virtual]

Stream this exportable object out to XML on a text stream.

Implements XmlExportable.

Definition at line 990 of file Document.cpp.

References PlayParameterRepository::getInstance(), XmlExportable::getObjectExportId(), PlayParameterRepository::getPlayParameters(), m_layers, m_layerViewMap, m_mainModel, m_models, PlayParameters::toXml(), WaveFileModel::toXml(), and writeBackwardCompatibleDerivation().

Referenced by MainWindowBase::toXml().

void Document::layerAdded ( Layer  )  [signal]

Referenced by createDerivedLayer(), createImportedLayer(), and createLayer().

void Document::layerRemoved ( Layer  )  [signal]

Referenced by deleteLayer().

void Document::layerAboutToBeDeleted ( Layer  )  [signal]

Referenced by deleteLayer().

void Document::layerInAView ( Layer ,
bool   
) [signal]

Referenced by addToLayerViewMap(), and removeFromLayerViewMap().

void Document::modelAdded ( Model  )  [signal]

Referenced by addDerivedModel(), addImportedModel(), and setMainModel().

void Document::mainModelChanged ( WaveFileModel  )  [signal]

Referenced by setMainModel(), and ~Document().

void Document::modelAboutToBeDeleted ( Model  )  [signal]

Referenced by Document(), releaseModel(), setMainModel(), and ~Document().

void Document::modelGenerationFailed ( QString  transformName,
QString  message 
) [signal]

Referenced by createDerivedLayer().

void Document::modelGenerationWarning ( QString  transformName,
QString  message 
) [signal]

Referenced by createDerivedLayer().

void Document::modelRegenerationFailed ( QString  layerName,
QString  transformName,
QString  message 
) [signal]

Referenced by setMainModel().

void Document::modelRegenerationWarning ( QString  layerName,
QString  transformName,
QString  message 
) [signal]

Referenced by setMainModel().

void Document::alignmentFailed ( QString  transformName,
QString  message 
) [signal]

Referenced by alignModel().

void Document::releaseModel ( Model model  )  [protected]

Definition at line 491 of file Document.cpp.

References Model::aboutToDelete(), m_mainModel, m_models, and modelAboutToBeDeleted().

Referenced by deleteLayer(), and setModel().

void Document::alignModel ( Model  )  [protected]

If model is suitable for alignment, align it against the main model and store the alignment in the model.

(If the model has an alignment already for the current main model, leave it unchanged.)

!! configure

Definition at line 784 of file Document.cpp.

References alignmentFailed(), Model::getAlignmentReference(), Transform::getBlockSize(), TransformFactory::getDefaultTransformFor(), ModelTransformerFactory::getInstance(), TransformFactory::getInstance(), Model::getSampleRate(), Transform::getStepSize(), m_mainModel, Model::setAlignment(), Transform::setParameter(), Transform::setStepSize(), and ModelTransformerFactory::transform().

Referenced by addImportedModel(), alignModels(), and setMainModel().

void Document::addToLayerViewMap ( Layer ,
View  
) [protected]

Definition at line 674 of file Document.cpp.

References layerInAView(), and m_layerViewMap.

Referenced by Document::AddLayerCommand::execute(), and Document::RemoveLayerCommand::unexecute().

void Document::removeFromLayerViewMap ( Layer ,
View  
) [protected]

Definition at line 692 of file Document.cpp.

References layerInAView(), and m_layerViewMap.

Referenced by Document::RemoveLayerCommand::execute(), and Document::AddLayerCommand::unexecute().

QString Document::getUniqueLayerName ( QString  candidate  )  [protected]

Definition at line 710 of file Document.cpp.

References m_layers.

Referenced by createDerivedLayer(), createImportedLayer(), and createLayer().

void Document::writeBackwardCompatibleDerivation ( QTextStream &  ,
QString  ,
Model ,
const ModelRecord  
) const [protected]

Definition at line 1078 of file Document.cpp.

References Document::ModelRecord::channel, XmlExportable::encodeEntities(), Transform::getBlockSize(), Transform::getDuration(), Transform::getIdentifier(), TransformFactory::getInstance(), XmlExportable::getObjectExportId(), TransformFactory::getPluginConfigurationXml(), Model::getSampleRate(), Transform::getStartTime(), Transform::getStepSize(), Transform::getWindowType(), RealTime::realTime2Frame(), Document::ModelRecord::source, Transform::toXml(), Document::ModelRecord::transform, and RealTime::zeroTime.

Referenced by toXml().

TransformId Document::getAlignmentTransformName (  )  [static, protected]

Definition at line 764 of file Document.cpp.

Referenced by canAlign().

QString XmlExportable::toXmlString ( QString  indent = "",
QString  extraAttributes = "" 
) const [virtual, inherited]

Convert this exportable object to XML in a string.

The default implementation calls toXml and returns the result as a string. Do not override this unless you really know what you're doing.

Definition at line 25 of file XmlExportable.cpp.

References XmlExportable::toXml().

Referenced by LayerFactory::setLayerDefaultProperties().

QString XmlExportable::encodeEntities ( QString   )  [static, inherited]

Definition at line 41 of file XmlExportable.cpp.

Referenced by AudioGenerator::getDefaultPlayPluginConfiguration(), SVFileReader::readPlugin(), Layer::toBriefXml(), WaveFileModel::toXml(), Transform::toXml(), TextPoint::toXml(), PluginXml::toXml(), Model::toXml(), Layer::toXml(), ImagePoint::toXml(), and writeBackwardCompatibleDerivation().

QString XmlExportable::encodeColour ( QColor   )  [static, inherited]

Definition at line 54 of file XmlExportable.cpp.

Referenced by ColourDatabase::getStringValues().

int XmlExportable::getObjectExportId ( const void *   )  [static, inherited]

Definition at line 71 of file XmlExportable.cpp.

Referenced by FFTDataServer::generateFileBasename(), View::getTextLabelHeight(), Layer::toBriefXml(), SparseModel< PointType >::toXml(), Model::toXml(), Layer::toXml(), EditableDenseThreeDimensionalModel::toXml(), toXml(), and writeBackwardCompatibleDerivation().


Member Data Documentation

WaveFileModel* Document::m_mainModel [protected]

The model that provides the underlying sample rate, etc.

This model is not reference counted for layers, and is not freed unless it is replaced or the document is deleted.

Definition at line 261 of file Document.h.

Referenced by addLayerToView(), alignModel(), alignModels(), createEmptyLayer(), createMainModelLayer(), getMainModel(), getTransformInputModels(), isKnownModel(), releaseModel(), setMainModel(), setModel(), toXml(), and ~Document().

ModelMap Document::m_models [protected]

Definition at line 285 of file Document.h.

Referenced by addDerivedModel(), addImportedModel(), addLayerToView(), alignModels(), getTransformInputModels(), isKnownModel(), releaseModel(), setMainModel(), setModel(), toXml(), and ~Document().

LayerViewMap Document::m_layerViewMap [protected]

Definition at line 324 of file Document.h.

Referenced by addToLayerViewMap(), deleteLayer(), removeFromLayerViewMap(), and toXml().

LayerSet Document::m_layers [protected]

Definition at line 340 of file Document.h.

Referenced by createImportedLayer(), createLayer(), deleteLayer(), getUniqueLayerName(), setMainModel(), toXml(), and ~Document().

bool Document::m_autoAlignment [protected]

Definition at line 342 of file Document.h.

Referenced by addImportedModel(), setAutoAlignment(), and setMainModel().


The documentation for this class was generated from the following files:
Generated on Wed Feb 20 15:45:32 2008 for SonicVisualiser by  doxygen 1.5.1