annotate base/PlayParameterRepository.cpp @ 82:bf42d8d63885

* Some work on reloading play parameters from file (not quite working yet) * Win32: redirect stderr to console * A bit of menu reorganisation
author Chris Cannam
date Wed, 26 Apr 2006 14:09:55 +0000
parents f277a171749d
children b2067aff8cd6
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@28 2
Chris@28 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@28 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@28 14 */
Chris@28 15
Chris@28 16 #include "PlayParameterRepository.h"
Chris@28 17 #include "PlayParameters.h"
Chris@28 18
Chris@30 19 //!!! shouldn't be including this here -- restructure needed
Chris@81 20
Chris@81 21 //!!! should the AudioGenerator actually implement all this stuff itself? do we even want this class?
Chris@30 22 #include "audioio/AudioGenerator.h"
Chris@30 23
Chris@29 24 #include <iostream>
Chris@29 25
Chris@28 26 PlayParameterRepository *
Chris@28 27 PlayParameterRepository::m_instance = new PlayParameterRepository;
Chris@28 28
Chris@28 29 PlayParameterRepository *
Chris@28 30 PlayParameterRepository::instance()
Chris@28 31 {
Chris@28 32 return m_instance;
Chris@28 33 }
Chris@28 34
Chris@28 35 PlayParameterRepository::~PlayParameterRepository()
Chris@28 36 {
Chris@28 37 }
Chris@28 38
Chris@30 39 void
Chris@30 40 PlayParameterRepository::addModel(const Model *model)
Chris@30 41 {
Chris@82 42 std::cerr << "PlayParameterRepository:addModel " << model << std::endl;
Chris@82 43
Chris@30 44 if (!getPlayParameters(model)) {
Chris@30 45
Chris@30 46 // Give all models the same type of play parameters for the
Chris@30 47 // moment, provided they can be played at all
Chris@30 48
Chris@30 49 if (AudioGenerator::canPlay(model)) {
Chris@30 50
Chris@30 51 std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl;
Chris@30 52
Chris@30 53 m_playParameters[model] = new PlayParameters;
Chris@30 54
Chris@57 55 m_playParameters[model]->setPlayPluginId
Chris@57 56 (AudioGenerator::getDefaultPlayPluginId(model));
Chris@57 57
Chris@57 58 m_playParameters[model]->setPlayPluginConfiguration
Chris@57 59 (AudioGenerator::getDefaultPlayPluginConfiguration(model));
Chris@57 60
Chris@30 61 connect(m_playParameters[model], SIGNAL(playParametersChanged()),
Chris@30 62 this, SLOT(playParametersChanged()));
Chris@30 63
Chris@57 64 connect(m_playParameters[model], SIGNAL(playPluginIdChanged(QString)),
Chris@57 65 this, SLOT(playPluginIdChanged(QString)));
Chris@57 66
Chris@57 67 connect(m_playParameters[model], SIGNAL(playPluginConfigurationChanged(QString)),
Chris@57 68 this, SLOT(playPluginConfigurationChanged(QString)));
Chris@57 69
Chris@30 70 } else {
Chris@30 71
Chris@30 72 std::cerr << "PlayParameterRepository: Model " << model << " not playable" << std::endl;
Chris@30 73 }
Chris@30 74 }
Chris@30 75 }
Chris@30 76
Chris@30 77 void
Chris@30 78 PlayParameterRepository::removeModel(const Model *model)
Chris@30 79 {
Chris@30 80 delete m_playParameters[model];
Chris@30 81 m_playParameters.erase(model);
Chris@30 82 }
Chris@30 83
Chris@28 84 PlayParameters *
Chris@30 85 PlayParameterRepository::getPlayParameters(const Model *model) const
Chris@28 86 {
Chris@30 87 if (m_playParameters.find(model) == m_playParameters.end()) return 0;
Chris@30 88 return m_playParameters.find(model)->second;
Chris@28 89 }
Chris@28 90
Chris@28 91 void
Chris@29 92 PlayParameterRepository::playParametersChanged()
Chris@29 93 {
Chris@57 94 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@57 95 emit playParametersChanged(params);
Chris@57 96 }
Chris@57 97
Chris@57 98 void
Chris@57 99 PlayParameterRepository::playPluginIdChanged(QString id)
Chris@57 100 {
Chris@57 101 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@57 102 for (ModelParameterMap::iterator i = m_playParameters.begin();
Chris@57 103 i != m_playParameters.end(); ++i) {
Chris@57 104 if (i->second == params) {
Chris@57 105 emit playPluginIdChanged(i->first, id);
Chris@57 106 return;
Chris@57 107 }
Chris@57 108 }
Chris@57 109 }
Chris@57 110
Chris@57 111 void
Chris@57 112 PlayParameterRepository::playPluginConfigurationChanged(QString config)
Chris@57 113 {
Chris@57 114 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@82 115 std::cerr << "PlayParameterRepository::playPluginConfigurationChanged" << std::endl;
Chris@57 116 for (ModelParameterMap::iterator i = m_playParameters.begin();
Chris@57 117 i != m_playParameters.end(); ++i) {
Chris@57 118 if (i->second == params) {
Chris@57 119 emit playPluginConfigurationChanged(i->first, config);
Chris@57 120 return;
Chris@57 121 }
Chris@57 122 }
Chris@29 123 }
Chris@29 124
Chris@29 125 void
Chris@28 126 PlayParameterRepository::clear()
Chris@28 127 {
Chris@30 128 std::cerr << "PlayParameterRepository: PlayParameterRepository::clear" << std::endl;
Chris@28 129 while (!m_playParameters.empty()) {
Chris@28 130 delete m_playParameters.begin()->second;
Chris@28 131 m_playParameters.erase(m_playParameters.begin());
Chris@28 132 }
Chris@28 133 }
Chris@28 134