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@391: #include "Playable.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@391: PlayParameterRepository::addPlayable(const Playable *playable) Chris@30: { Chris@847: cerr << "PlayParameterRepository:addPlayable playable = " << playable << endl; Chris@82: Chris@391: if (!getPlayParameters(playable)) { Chris@30: Chris@391: // Give all playables the same type of play parameters for the Chris@391: // moment Chris@30: Chris@847: cerr << "PlayParameterRepository:addPlayable: Adding play parameters for " << playable << endl; Chris@30: Chris@391: PlayParameters *params = new PlayParameters; Chris@391: m_playParameters[playable] = params; Chris@30: Chris@866: params->setPlayClipId Chris@866: (playable->getDefaultPlayClipId()); Chris@952: Chris@952: params->setPlayAudible Chris@952: (playable->getDefaultPlayAudible()); Chris@391: Chris@391: connect(params, SIGNAL(playParametersChanged()), Chris@391: this, SLOT(playParametersChanged())); Chris@391: Chris@866: connect(params, SIGNAL(playClipIdChanged(QString)), Chris@866: this, SLOT(playClipIdChanged(QString))); Chris@30: Chris@847: cerr << "Connected play parameters " << params << " for playable " Chris@847: << playable << " to this " << this << endl; Chris@30: } Chris@30: } Chris@30: Chris@30: void Chris@391: PlayParameterRepository::removePlayable(const Playable *playable) Chris@30: { Chris@391: if (m_playParameters.find(playable) == m_playParameters.end()) { Chris@843: cerr << "WARNING: PlayParameterRepository::removePlayable: unknown playable " << playable << endl; Chris@391: return; Chris@391: } Chris@391: delete m_playParameters[playable]; Chris@391: m_playParameters.erase(playable); Chris@30: } Chris@30: Chris@284: void Chris@391: PlayParameterRepository::copyParameters(const Playable *from, const Playable *to) Chris@284: { Chris@284: if (!getPlayParameters(from)) { Chris@843: cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << endl; Chris@284: return; Chris@284: } Chris@284: if (!getPlayParameters(to)) { Chris@843: cerr << "WARNING: PlayParameterRepository::copyParameters: target playable unknown, adding it now" << endl; Chris@391: addPlayable(to); Chris@284: } Chris@284: getPlayParameters(to)->copyFrom(getPlayParameters(from)); Chris@284: } Chris@284: Chris@28: PlayParameters * Chris@391: PlayParameterRepository::getPlayParameters(const Playable *playable) Chris@28: { Chris@391: if (m_playParameters.find(playable) == m_playParameters.end()) return 0; Chris@391: return m_playParameters.find(playable)->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@866: PlayParameterRepository::playClipIdChanged(QString id) Chris@57: { Chris@57: PlayParameters *params = dynamic_cast(sender()); Chris@391: for (PlayableParameterMap::iterator i = m_playParameters.begin(); Chris@57: i != m_playParameters.end(); ++i) { Chris@57: if (i->second == params) { Chris@866: emit playClipIdChanged(i->first, id); Chris@57: return; Chris@57: } Chris@57: } Chris@29: } Chris@29: Chris@29: void Chris@28: PlayParameterRepository::clear() Chris@28: { Chris@843: // cerr << "PlayParameterRepository: PlayParameterRepository::clear" << 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: Chris@391: PlayParameterRepository::EditCommand::EditCommand(PlayParameters *params) : Chris@391: m_params(params) Chris@391: { Chris@391: m_from.copyFrom(m_params); Chris@391: m_to.copyFrom(m_params); Chris@391: } Chris@391: Chris@391: void Chris@391: PlayParameterRepository::EditCommand::setPlayMuted(bool muted) Chris@391: { Chris@391: m_to.setPlayMuted(muted); Chris@391: } Chris@391: Chris@391: void Chris@391: PlayParameterRepository::EditCommand::setPlayAudible(bool audible) Chris@391: { Chris@391: m_to.setPlayAudible(audible); Chris@391: } Chris@391: Chris@391: void Chris@391: PlayParameterRepository::EditCommand::setPlayPan(float pan) Chris@391: { Chris@391: m_to.setPlayPan(pan); Chris@391: } Chris@391: Chris@391: void Chris@391: PlayParameterRepository::EditCommand::setPlayGain(float gain) Chris@391: { Chris@391: m_to.setPlayGain(gain); Chris@391: } Chris@391: Chris@391: void Chris@866: PlayParameterRepository::EditCommand::setPlayClipId(QString id) Chris@391: { Chris@866: m_to.setPlayClipId(id); Chris@391: } Chris@391: Chris@391: void Chris@391: PlayParameterRepository::EditCommand::execute() Chris@391: { Chris@391: m_params->copyFrom(&m_to); Chris@391: } Chris@391: Chris@391: void Chris@391: PlayParameterRepository::EditCommand::unexecute() Chris@391: { Chris@391: m_params->copyFrom(&m_from); Chris@391: } Chris@391: Chris@391: QString Chris@391: PlayParameterRepository::EditCommand::getName() const Chris@391: { Chris@391: QString name; Chris@391: QString multiname = tr("Adjust Playback Parameters"); Chris@391: Chris@391: int changed = 0; Chris@391: Chris@391: if (m_to.isPlayAudible() != m_from.isPlayAudible()) { Chris@391: name = tr("Change Playback Mute State"); Chris@391: if (++changed > 1) return multiname; Chris@391: } Chris@391: Chris@391: if (m_to.getPlayGain() != m_from.getPlayGain()) { Chris@391: name = tr("Change Playback Gain"); Chris@391: if (++changed > 1) return multiname; Chris@391: } Chris@391: Chris@391: if (m_to.getPlayPan() != m_from.getPlayPan()) { Chris@391: name = tr("Change Playback Pan"); Chris@391: if (++changed > 1) return multiname; Chris@391: } Chris@391: Chris@866: if (m_to.getPlayClipId() != m_from.getPlayClipId()) { Chris@863: name = tr("Change Playback Sample"); Chris@391: if (++changed > 1) return multiname; Chris@391: } Chris@391: Chris@391: if (name == "") return multiname; Chris@391: return name; Chris@391: } Chris@391: