annotate base/PlayParameterRepository.cpp @ 348:edda24bb85fc

* Skip ID3 block when reading MP3 files (so long as ID3 support is included) * Show progress when retrieving audio file from playlist * Avoid -- but do not actually fix -- segmentation fault on exit. I am totally stumped at the moment about why both the PA and JACK audio targets should crash when properly shut down. For the moment, we just don't shut them down... * Fix incorrect behaviour (introduced on Friday as part of a different fix) when replacing main model in situation where no current main model exists
author Chris Cannam
date Fri, 30 Nov 2007 17:31:09 +0000
parents 1dc99b430d2a
children 5858cc462d0a
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@321 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@145 30 PlayParameterRepository::getInstance()
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@117 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@117 51 // std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl;
Chris@30 52
Chris@83 53 PlayParameters *params = new PlayParameters;
Chris@83 54 m_playParameters[model] = params;
Chris@30 55
Chris@83 56 params->setPlayPluginId
Chris@57 57 (AudioGenerator::getDefaultPlayPluginId(model));
Chris@57 58
Chris@83 59 params->setPlayPluginConfiguration
Chris@57 60 (AudioGenerator::getDefaultPlayPluginConfiguration(model));
Chris@57 61
Chris@83 62 connect(params, SIGNAL(playParametersChanged()),
Chris@30 63 this, SLOT(playParametersChanged()));
Chris@30 64
Chris@83 65 connect(params, SIGNAL(playPluginIdChanged(QString)),
Chris@57 66 this, SLOT(playPluginIdChanged(QString)));
Chris@57 67
Chris@83 68 connect(params, SIGNAL(playPluginConfigurationChanged(QString)),
Chris@57 69 this, SLOT(playPluginConfigurationChanged(QString)));
Chris@57 70
Chris@117 71 // std::cerr << "Connected play parameters " << params << " for model "
Chris@117 72 // << model << " to this " << this << std::endl;
Chris@83 73
Chris@30 74 } else {
Chris@30 75
Chris@117 76 // std::cerr << "PlayParameterRepository: Model " << model << " not playable" << std::endl;
Chris@30 77 }
Chris@30 78 }
Chris@30 79 }
Chris@30 80
Chris@30 81 void
Chris@30 82 PlayParameterRepository::removeModel(const Model *model)
Chris@30 83 {
Chris@30 84 delete m_playParameters[model];
Chris@30 85 m_playParameters.erase(model);
Chris@30 86 }
Chris@30 87
Chris@284 88 void
Chris@284 89 PlayParameterRepository::copyParameters(const Model *from, const Model *to)
Chris@284 90 {
Chris@284 91 if (!getPlayParameters(from)) {
Chris@284 92 std::cerr << "ERROR: PlayParameterRepository::copyParameters: source model unknown" << std::endl;
Chris@284 93 return;
Chris@284 94 }
Chris@284 95 if (!getPlayParameters(to)) {
Chris@284 96 std::cerr << "WARNING: PlayParameterRepository::copyParameters: target model unknown, adding it now" << std::endl;
Chris@284 97 addModel(to);
Chris@284 98 }
Chris@284 99 getPlayParameters(to)->copyFrom(getPlayParameters(from));
Chris@284 100 }
Chris@284 101
Chris@28 102 PlayParameters *
Chris@284 103 PlayParameterRepository::getPlayParameters(const Model *model)
Chris@28 104 {
Chris@30 105 if (m_playParameters.find(model) == m_playParameters.end()) return 0;
Chris@30 106 return m_playParameters.find(model)->second;
Chris@28 107 }
Chris@28 108
Chris@28 109 void
Chris@29 110 PlayParameterRepository::playParametersChanged()
Chris@29 111 {
Chris@57 112 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@57 113 emit playParametersChanged(params);
Chris@57 114 }
Chris@57 115
Chris@57 116 void
Chris@57 117 PlayParameterRepository::playPluginIdChanged(QString id)
Chris@57 118 {
Chris@57 119 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@57 120 for (ModelParameterMap::iterator i = m_playParameters.begin();
Chris@57 121 i != m_playParameters.end(); ++i) {
Chris@57 122 if (i->second == params) {
Chris@57 123 emit playPluginIdChanged(i->first, id);
Chris@57 124 return;
Chris@57 125 }
Chris@57 126 }
Chris@57 127 }
Chris@57 128
Chris@57 129 void
Chris@57 130 PlayParameterRepository::playPluginConfigurationChanged(QString config)
Chris@57 131 {
Chris@57 132 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@117 133 // std::cerr << "PlayParameterRepository::playPluginConfigurationChanged" << std::endl;
Chris@57 134 for (ModelParameterMap::iterator i = m_playParameters.begin();
Chris@57 135 i != m_playParameters.end(); ++i) {
Chris@57 136 if (i->second == params) {
Chris@57 137 emit playPluginConfigurationChanged(i->first, config);
Chris@57 138 return;
Chris@57 139 }
Chris@57 140 }
Chris@29 141 }
Chris@29 142
Chris@29 143 void
Chris@28 144 PlayParameterRepository::clear()
Chris@28 145 {
Chris@117 146 // std::cerr << "PlayParameterRepository: PlayParameterRepository::clear" << std::endl;
Chris@28 147 while (!m_playParameters.empty()) {
Chris@28 148 delete m_playParameters.begin()->second;
Chris@28 149 m_playParameters.erase(m_playParameters.begin());
Chris@28 150 }
Chris@28 151 }
Chris@28 152