Fix more broken indentation (whitespace changes only).
[ardour.git] / libs / ardour / speakers.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "ardour/speaker.h"
20 #include "ardour/speakers.h"
21
22 using namespace ARDOUR;
23 using namespace PBD;
24 using namespace std;
25
26 Speaker::Speaker (int i, const AngularVector& position)
27         : id (i)
28 {
29         move (position);
30 }
31
32 void
33 Speaker::move (const AngularVector& new_position)
34 {
35         _angles = new_position;
36         _angles.cartesian (_coords);
37 }
38
39 Speakers::Speakers ()
40 {
41 }
42
43 Speakers::~Speakers ()
44 {
45 }
46
47 void
48 Speakers::dump_speakers (ostream& o)
49 {
50         for (vector<Speaker>::iterator i = _speakers.begin(); i != _speakers.end(); ++i) {
51                 o << "Speaker " << (*i).id << " @ " 
52                   << (*i).coords().x << ", " << (*i).coords().y << ", " << (*i).coords().z
53                   << " azimuth " << (*i).angles().azi
54                   << " elevation " << (*i).angles().ele
55                   << " distance " << (*i).angles().length
56                   << endl;
57         }
58 }
59
60 void
61 Speakers::clear_speakers ()
62 {
63         _speakers.clear ();
64         update ();
65 }
66
67 int 
68 Speakers::add_speaker (const AngularVector& position)
69 {
70         int id = _speakers.size();
71
72         cerr << "Added speaker " << id << " at " << position.azi << " /= " << position.ele << endl;
73
74         _speakers.push_back (Speaker (id, position));
75         update ();
76
77         dump_speakers (cerr);
78         Changed ();
79
80         return id;
81 }        
82
83 void
84 Speakers::remove_speaker (int id)
85 {
86         for (vector<Speaker>::iterator i = _speakers.begin(); i != _speakers.end(); ) {
87                 if ((*i).id == id) {
88                         i = _speakers.erase (i);
89                         update ();
90                         break;
91                 } 
92         }
93 }
94
95 void
96 Speakers::move_speaker (int id, const AngularVector& new_position)
97 {
98         for (vector<Speaker>::iterator i = _speakers.begin(); i != _speakers.end(); ++i) {
99                 if ((*i).id == id) {
100                         (*i).move (new_position);
101                         update ();
102                         break;
103                 }
104         }
105 }