Nsound  0.9.4
BufferSelection.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: BufferSelection.cc 912 2015-07-26 00:50:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2009-Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 
34 #include <Nsound/Buffer.h>
35 
36 using namespace Nsound;
37 
40 BufferSelection(Buffer & buffer, const BooleanVector & bv)
41  :
42  target_buffer_(&buffer),
43  bv_(bv)
44 {
45 };
46 
50  :
51  target_buffer_(copy.target_buffer_),
52  bv_(copy.bv_)
53 {
54 };
55 
60 {
61  if(this == & rhs)
62  {
63  return *this;
64  }
65 
66  target_buffer_ = rhs.target_buffer_;
67  bv_ = rhs.bv_;
68  return *this;
69 };
70 
74 operator+=(const float64 & rhs)
75 {
76  Buffer::iterator b = target_buffer_->begin();
77  Buffer::iterator b_end = target_buffer_->end();
78 
79  BooleanVector::iterator bv = bv_.begin();
80  BooleanVector::iterator bv_end = bv_.end();
81 
82  while(b != b_end && bv != bv_end)
83  {
84  if(*bv) *b += rhs;
85  ++b;
86  ++bv;
87  }
88 
89  return *this;
90 }
91 
95 operator-=(const float64 & rhs)
96 {
97  Buffer::iterator b = target_buffer_->begin();
98  Buffer::iterator b_end = target_buffer_->end();
99 
100  BooleanVector::iterator bv = bv_.begin();
101  BooleanVector::iterator bv_end = bv_.end();
102 
103  while(b != b_end && bv != bv_end)
104  {
105  if(*bv) *b -= rhs;
106  ++b;
107  ++bv;
108  }
109 
110  return *this;
111 }
112 
114 Nsound::
116 operator*=(const float64 & rhs)
117 {
118  Buffer::iterator b = this->target_buffer_->begin();
119  Buffer::iterator b_end = this->target_buffer_->end();
120 
121  BooleanVector::iterator bv = this->bv_.begin();
122  BooleanVector::iterator bv_end = this->bv_.end();
123 
124  while(b != b_end && bv != bv_end)
125  {
126  if(*bv) *b *= rhs;
127  ++b;
128  ++bv;
129  }
130 
131  return *this;
132 }
133 
135 Nsound::
137 operator/=(const float64 & rhs)
138 {
139  Buffer::iterator b = this->target_buffer_->begin();
140  Buffer::iterator b_end = this->target_buffer_->end();
141 
142  BooleanVector::iterator bv = this->bv_.begin();
143  BooleanVector::iterator bv_end = this->bv_.end();
144 
145  while(b != b_end && bv != bv_end)
146  {
147  if(*bv) *b /= rhs;
148  ++b;
149  ++bv;
150  }
151 
152  return *this;
153 }
154 
156 Nsound::
158 operator^=(const float64 & rhs)
159 {
160  Buffer::iterator b = this->target_buffer_->begin();
161  Buffer::iterator b_end = this->target_buffer_->end();
162 
163  BooleanVector::iterator bv = this->bv_.begin();
164  BooleanVector::iterator bv_end = this->bv_.end();
165 
166  while(b != b_end && bv != bv_end)
167  {
168  if(*bv) std::pow(*b, rhs);
169  ++b;
170  ++bv;
171  }
172 
173  return *this;
174 }
175 
177 Nsound::
179 operator=(const float64 & rhs)
180 {
181  Buffer::iterator b = this->target_buffer_->begin();
182  Buffer::iterator b_end = this->target_buffer_->end();
183 
184  BooleanVector::iterator bv = this->bv_.begin();
185  BooleanVector::iterator bv_end = this->bv_.end();
186 
187  while(b != b_end && bv != bv_end)
188  {
189  if(*bv) *b = rhs;
190  ++b;
191  ++bv;
192  }
193 
194  return *this;
195 }
196 
BufferSelection(Buffer &buffer, const BooleanVector &bv)
BufferSelection & operator^=(const float64 &rhs)
double float64
Definition: Nsound.h:146
BufferSelection & operator=(const BufferSelection &rhs)
BufferSelection & operator/=(const float64 &rhs)
BufferSelection & operator+=(const float64 &rhs)
A Buffer for storing audio samples.
Definition: Buffer.h:60
std::vector< boolean > BooleanVector
FloatVector::iterator iterator
Definition: Buffer.h:69
A helper class for advance operators.
BufferSelection & operator-=(const float64 &rhs)
BufferSelection & operator*=(const float64 &rhs)