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@30
|
20 #include "audioio/AudioGenerator.h"
|
Chris@30
|
21
|
Chris@29
|
22 #include <iostream>
|
Chris@29
|
23
|
Chris@28
|
24 PlayParameterRepository *
|
Chris@28
|
25 PlayParameterRepository::m_instance = new PlayParameterRepository;
|
Chris@28
|
26
|
Chris@28
|
27 PlayParameterRepository *
|
Chris@28
|
28 PlayParameterRepository::instance()
|
Chris@28
|
29 {
|
Chris@28
|
30 return m_instance;
|
Chris@28
|
31 }
|
Chris@28
|
32
|
Chris@28
|
33 PlayParameterRepository::~PlayParameterRepository()
|
Chris@28
|
34 {
|
Chris@28
|
35 }
|
Chris@28
|
36
|
Chris@30
|
37 void
|
Chris@30
|
38 PlayParameterRepository::addModel(const Model *model)
|
Chris@30
|
39 {
|
Chris@30
|
40 if (!getPlayParameters(model)) {
|
Chris@30
|
41
|
Chris@30
|
42 // Give all models the same type of play parameters for the
|
Chris@30
|
43 // moment, provided they can be played at all
|
Chris@30
|
44
|
Chris@30
|
45 if (AudioGenerator::canPlay(model)) {
|
Chris@30
|
46
|
Chris@30
|
47 std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl;
|
Chris@30
|
48
|
Chris@30
|
49 m_playParameters[model] = new PlayParameters;
|
Chris@30
|
50
|
Chris@30
|
51 connect(m_playParameters[model], SIGNAL(playParametersChanged()),
|
Chris@30
|
52 this, SLOT(playParametersChanged()));
|
Chris@30
|
53
|
Chris@30
|
54 } else {
|
Chris@30
|
55
|
Chris@30
|
56 std::cerr << "PlayParameterRepository: Model " << model << " not playable" << std::endl;
|
Chris@30
|
57 }
|
Chris@30
|
58 }
|
Chris@30
|
59 }
|
Chris@30
|
60
|
Chris@30
|
61 void
|
Chris@30
|
62 PlayParameterRepository::removeModel(const Model *model)
|
Chris@30
|
63 {
|
Chris@30
|
64 delete m_playParameters[model];
|
Chris@30
|
65 m_playParameters.erase(model);
|
Chris@30
|
66 }
|
Chris@30
|
67
|
Chris@28
|
68 PlayParameters *
|
Chris@30
|
69 PlayParameterRepository::getPlayParameters(const Model *model) const
|
Chris@28
|
70 {
|
Chris@30
|
71 if (m_playParameters.find(model) == m_playParameters.end()) return 0;
|
Chris@30
|
72 return m_playParameters.find(model)->second;
|
Chris@28
|
73 }
|
Chris@28
|
74
|
Chris@28
|
75 void
|
Chris@29
|
76 PlayParameterRepository::playParametersChanged()
|
Chris@29
|
77 {
|
Chris@29
|
78 emit playParametersChanged(dynamic_cast<PlayParameters *>(sender()));
|
Chris@29
|
79 }
|
Chris@29
|
80
|
Chris@29
|
81 void
|
Chris@28
|
82 PlayParameterRepository::clear()
|
Chris@28
|
83 {
|
Chris@30
|
84 std::cerr << "PlayParameterRepository: PlayParameterRepository::clear" << std::endl;
|
Chris@28
|
85 while (!m_playParameters.empty()) {
|
Chris@28
|
86 delete m_playParameters.begin()->second;
|
Chris@28
|
87 m_playParameters.erase(m_playParameters.begin());
|
Chris@28
|
88 }
|
Chris@28
|
89 }
|
Chris@28
|
90
|