annotate layer/Layer.cpp @ 182:42118892f428

* Update copyright notes as appropriate.
author Chris Cannam
date Fri, 17 Nov 2006 16:27:39 +0000
parents eaae73b6bd28
children 258af0c4dc28
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@127 46 QString layerName = objectName();
Chris@127 47 QString modelName;
Chris@127 48 if (getModel()) modelName = getModel()->objectName();
Chris@127 49
Chris@127 50 QString text;
Chris@127 51 if (modelName != "") {
Chris@127 52 text = QString("%1: %2").arg(modelName).arg(layerName);
Chris@127 53 } else {
Chris@127 54 text = layerName;
Chris@127 55 }
Chris@127 56
Chris@127 57 return text;
Chris@127 58 }
Chris@127 59
Chris@127 60 void
Chris@127 61 Layer::setObjectName(const QString &name)
Chris@127 62 {
Chris@127 63 QObject::setObjectName(name);
Chris@127 64 emit layerNameChanged();
Chris@127 65 }
Chris@127 66
Chris@127 67 QString
Chris@127 68 Layer::toXmlString(QString indent, QString extraAttributes) const
Chris@127 69 {
Chris@127 70 QString s;
Chris@127 71
Chris@127 72 s += indent;
Chris@127 73
Chris@127 74 s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n")
Chris@127 75 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
Chris@127 76 (LayerFactory::getInstance()->getLayerType(this))))
Chris@127 77 .arg(getObjectExportId(this))
Chris@127 78 .arg(encodeEntities(objectName()))
Chris@127 79 .arg(getObjectExportId(getModel()))
Chris@127 80 .arg(extraAttributes);
Chris@127 81
Chris@127 82 return s;
Chris@127 83 }
Chris@127 84
Chris@127 85 PlayParameters *
Chris@127 86 Layer::getPlayParameters()
Chris@127 87 {
Chris@127 88 // std::cerr << "Layer (" << this << ", " << objectName().toStdString() << ")::getPlayParameters: model is "<< getModel() << std::endl;
Chris@127 89 const Model *model = getModel();
Chris@127 90 if (model) {
Chris@127 91 return PlayParameterRepository::getInstance()->getPlayParameters(model);
Chris@127 92 }
Chris@127 93 return 0;
Chris@127 94 }
Chris@127 95
Chris@127 96 void
Chris@131 97 Layer::setLayerDormant(const View *v, bool dormant)
Chris@131 98 {
Chris@131 99 const void *vv = (const void *)v;
Chris@131 100 QMutexLocker locker(&m_dormancyMutex);
Chris@131 101 m_dormancy[vv] = dormant;
Chris@131 102 }
Chris@131 103
Chris@131 104 bool
Chris@131 105 Layer::isLayerDormant(const View *v) const
Chris@131 106 {
Chris@131 107 const void *vv = (const void *)v;
Chris@131 108 QMutexLocker locker(&m_dormancyMutex);
Chris@131 109 if (m_dormancy.find(vv) == m_dormancy.end()) return false;
Chris@131 110 return m_dormancy.find(vv)->second;
Chris@131 111 }
Chris@131 112
Chris@131 113 void
Chris@127 114 Layer::showLayer(View *view, bool show)
Chris@127 115 {
Chris@127 116 setLayerDormant(view, !show);
Chris@127 117 emit layerParametersChanged();
Chris@127 118 }
Chris@127 119
Chris@127 120
Chris@127 121 #ifdef INCLUDE_MOCFILES
Chris@127 122 #include "Layer.moc.cpp"
Chris@127 123 #endif
Chris@127 124