annotate layer/Layer.cpp @ 239:6e59a60139b7

...
author Chris Cannam
date Mon, 23 Apr 2007 12:14:10 +0000
parents 6969f21da18a
children 6d113226bb4c
rev   line source
Chris@127 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@127 2
Chris@127 3 /*
Chris@127 4 Sonic Visualiser
Chris@127 5 An audio file viewer and annotation editor.
Chris@127 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@127 8
Chris@127 9 This program is free software; you can redistribute it and/or
Chris@127 10 modify it under the terms of the GNU General Public License as
Chris@127 11 published by the Free Software Foundation; either version 2 of the
Chris@127 12 License, or (at your option) any later version. See the file
Chris@127 13 COPYING included with this distribution for more information.
Chris@127 14 */
Chris@127 15
Chris@127 16 #include "Layer.h"
Chris@128 17 #include "view/View.h"
Chris@128 18 #include "data/model/Model.h"
Chris@127 19
Chris@127 20 #include <iostream>
Chris@127 21
Chris@131 22 #include <QMutexLocker>
Chris@131 23
Chris@131 24 #include "LayerFactory.h"
Chris@128 25 #include "base/PlayParameterRepository.h"
Chris@127 26
Chris@127 27 Layer::Layer()
Chris@127 28 {
Chris@127 29 }
Chris@127 30
Chris@127 31 Layer::~Layer()
Chris@127 32 {
Chris@127 33 // std::cerr << "Layer::~Layer(" << this << ")" << std::endl;
Chris@127 34 }
Chris@127 35
Chris@127 36 QString
Chris@127 37 Layer::getPropertyContainerIconName() const
Chris@127 38 {
Chris@127 39 return LayerFactory::getInstance()->getLayerIconName
Chris@127 40 (LayerFactory::getInstance()->getLayerType(this));
Chris@127 41 }
Chris@127 42
Chris@127 43 QString
Chris@127 44 Layer::getLayerPresentationName() const
Chris@127 45 {
Chris@203 46 // QString layerName = objectName();
Chris@203 47
Chris@203 48 LayerFactory *factory = LayerFactory::getInstance();
Chris@203 49 QString layerName = factory->getLayerPresentationName
Chris@203 50 (factory->getLayerType(this));
Chris@203 51
Chris@127 52 QString modelName;
Chris@127 53 if (getModel()) modelName = getModel()->objectName();
Chris@127 54
Chris@127 55 QString text;
Chris@127 56 if (modelName != "") {
Chris@127 57 text = QString("%1: %2").arg(modelName).arg(layerName);
Chris@127 58 } else {
Chris@127 59 text = layerName;
Chris@127 60 }
Chris@127 61
Chris@127 62 return text;
Chris@127 63 }
Chris@127 64
Chris@127 65 void
Chris@127 66 Layer::setObjectName(const QString &name)
Chris@127 67 {
Chris@127 68 QObject::setObjectName(name);
Chris@127 69 emit layerNameChanged();
Chris@127 70 }
Chris@127 71
Chris@127 72 QString
Chris@127 73 Layer::toXmlString(QString indent, QString extraAttributes) const
Chris@127 74 {
Chris@127 75 QString s;
Chris@127 76
Chris@127 77 s += indent;
Chris@127 78
Chris@127 79 s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n")
Chris@127 80 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
Chris@127 81 (LayerFactory::getInstance()->getLayerType(this))))
Chris@127 82 .arg(getObjectExportId(this))
Chris@127 83 .arg(encodeEntities(objectName()))
Chris@127 84 .arg(getObjectExportId(getModel()))
Chris@127 85 .arg(extraAttributes);
Chris@127 86
Chris@127 87 return s;
Chris@127 88 }
Chris@127 89
Chris@127 90 PlayParameters *
Chris@127 91 Layer::getPlayParameters()
Chris@127 92 {
Chris@127 93 // std::cerr << "Layer (" << this << ", " << objectName().toStdString() << ")::getPlayParameters: model is "<< getModel() << std::endl;
Chris@127 94 const Model *model = getModel();
Chris@127 95 if (model) {
Chris@127 96 return PlayParameterRepository::getInstance()->getPlayParameters(model);
Chris@127 97 }
Chris@127 98 return 0;
Chris@127 99 }
Chris@127 100
Chris@127 101 void
Chris@131 102 Layer::setLayerDormant(const View *v, bool dormant)
Chris@131 103 {
Chris@131 104 const void *vv = (const void *)v;
Chris@131 105 QMutexLocker locker(&m_dormancyMutex);
Chris@131 106 m_dormancy[vv] = dormant;
Chris@131 107 }
Chris@131 108
Chris@131 109 bool
Chris@131 110 Layer::isLayerDormant(const View *v) const
Chris@131 111 {
Chris@131 112 const void *vv = (const void *)v;
Chris@131 113 QMutexLocker locker(&m_dormancyMutex);
Chris@131 114 if (m_dormancy.find(vv) == m_dormancy.end()) return false;
Chris@131 115 return m_dormancy.find(vv)->second;
Chris@131 116 }
Chris@131 117
Chris@131 118 void
Chris@127 119 Layer::showLayer(View *view, bool show)
Chris@127 120 {
Chris@127 121 setLayerDormant(view, !show);
Chris@127 122 emit layerParametersChanged();
Chris@127 123 }
Chris@127 124