Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@28: Chris@28: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@52: This file copyright 2006 Chris Cannam. Chris@28: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@28: */ Chris@28: Chris@28: #include "PlayParameterRepository.h" Chris@28: #include "PlayParameters.h" Chris@28: Chris@30: //!!! shouldn't be including this here -- restructure needed Chris@81: Chris@81: //!!! should the AudioGenerator actually implement all this stuff itself? do we even want this class? Chris@150: #include "sv/audioio/AudioGenerator.h" Chris@30: Chris@29: #include Chris@29: Chris@28: PlayParameterRepository * Chris@28: PlayParameterRepository::m_instance = new PlayParameterRepository; Chris@28: Chris@28: PlayParameterRepository * Chris@145: PlayParameterRepository::getInstance() Chris@28: { Chris@28: return m_instance; Chris@28: } Chris@28: Chris@28: PlayParameterRepository::~PlayParameterRepository() Chris@28: { Chris@28: } Chris@28: Chris@30: void Chris@30: PlayParameterRepository::addModel(const Model *model) Chris@30: { Chris@117: // std::cerr << "PlayParameterRepository:addModel " << model << std::endl; Chris@82: Chris@30: if (!getPlayParameters(model)) { Chris@30: Chris@30: // Give all models the same type of play parameters for the Chris@30: // moment, provided they can be played at all Chris@30: Chris@30: if (AudioGenerator::canPlay(model)) { Chris@30: Chris@117: // std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl; Chris@30: Chris@83: PlayParameters *params = new PlayParameters; Chris@83: m_playParameters[model] = params; Chris@30: Chris@83: params->setPlayPluginId Chris@57: (AudioGenerator::getDefaultPlayPluginId(model)); Chris@57: Chris@83: params->setPlayPluginConfiguration Chris@57: (AudioGenerator::getDefaultPlayPluginConfiguration(model)); Chris@57: Chris@83: connect(params, SIGNAL(playParametersChanged()), Chris@30: this, SLOT(playParametersChanged())); Chris@30: Chris@83: connect(params, SIGNAL(playPluginIdChanged(QString)), Chris@57: this, SLOT(playPluginIdChanged(QString))); Chris@57: Chris@83: connect(params, SIGNAL(playPluginConfigurationChanged(QString)), Chris@57: this, SLOT(playPluginConfigurationChanged(QString))); Chris@57: Chris@117: // std::cerr << "Connected play parameters " << params << " for model " Chris@117: // << model << " to this " << this << std::endl; Chris@83: Chris@30: } else { Chris@30: Chris@117: // std::cerr << "PlayParameterRepository: Model " << model << " not playable" << std::endl; Chris@30: } Chris@30: } Chris@30: } Chris@30: Chris@30: void Chris@30: PlayParameterRepository::removeModel(const Model *model) Chris@30: { Chris@30: delete m_playParameters[model]; Chris@30: m_playParameters.erase(model); Chris@30: } Chris@30: Chris@28: PlayParameters * Chris@30: PlayParameterRepository::getPlayParameters(const Model *model) const Chris@28: { Chris@30: if (m_playParameters.find(model) == m_playParameters.end()) return 0; Chris@30: return m_playParameters.find(model)->second; Chris@28: } Chris@28: Chris@28: void Chris@29: PlayParameterRepository::playParametersChanged() Chris@29: { Chris@57: PlayParameters *params = dynamic_cast(sender()); Chris@57: emit playParametersChanged(params); Chris@57: } Chris@57: Chris@57: void Chris@57: PlayParameterRepository::playPluginIdChanged(QString id) Chris@57: { Chris@57: PlayParameters *params = dynamic_cast(sender()); Chris@57: for (ModelParameterMap::iterator i = m_playParameters.begin(); Chris@57: i != m_playParameters.end(); ++i) { Chris@57: if (i->second == params) { Chris@57: emit playPluginIdChanged(i->first, id); Chris@57: return; Chris@57: } Chris@57: } Chris@57: } Chris@57: Chris@57: void Chris@57: PlayParameterRepository::playPluginConfigurationChanged(QString config) Chris@57: { Chris@57: PlayParameters *params = dynamic_cast(sender()); Chris@117: // std::cerr << "PlayParameterRepository::playPluginConfigurationChanged" << std::endl; Chris@57: for (ModelParameterMap::iterator i = m_playParameters.begin(); Chris@57: i != m_playParameters.end(); ++i) { Chris@57: if (i->second == params) { Chris@57: emit playPluginConfigurationChanged(i->first, config); Chris@57: return; Chris@57: } Chris@57: } Chris@29: } Chris@29: Chris@29: void Chris@28: PlayParameterRepository::clear() Chris@28: { Chris@117: // std::cerr << "PlayParameterRepository: PlayParameterRepository::clear" << std::endl; Chris@28: while (!m_playParameters.empty()) { Chris@28: delete m_playParameters.begin()->second; Chris@28: m_playParameters.erase(m_playParameters.begin()); Chris@28: } Chris@28: } Chris@28: