00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "common.h"
00020 #include "MarControlValue.h"
00021 #include "MarControl.h"
00022 #include "MarControlManager.h"
00023 #include <algorithm>
00024
00025
00026 using std::ostringstream;
00027 using namespace Marsyas;
00028
00029
00030
00031
00032
00033
00034 void
00035 MarControlValue::setDebugValue()
00036 {
00037 #ifdef MARSYAS_TRACECONTROLS
00038 ostringstream oss;
00039 serialize(oss);
00040 value_debug_ = oss.str();
00041 #endif
00042 }
00043
00044
00045
00046 mrs_string
00047 MarControlValue::getType() const
00048 {
00049 return type_;
00050 }
00051
00052 mrs_string
00053 MarControlValue::getRegisteredType()
00054 {
00055 return MarControlManager::getManager()->getRegisteredType(this->getTypeID());
00056 }
00057
00058
00059 void
00060 MarControlValue::current_link_update()
00061 {
00062 current_link_->callMarSystemUpdate();
00063 }
00064
00065
00066
00067
00068
00069 realvec MarControlValueT<realvec>::invalidValue;
00070
00071
00072 MarControlValueT<realvec>::MarControlValueT(realvec value)
00073 {
00074 value_ = value;
00075 type_ = "mrs_realvec";
00076
00077 setDebugValue();
00078 }
00079
00080 MarControlValueT<realvec>::MarControlValueT(const MarControlValueT& a):MarControlValue(a)
00081 {
00082 value_ = a.value_;
00083 type_ = "mrs_realvec";
00084
00085 setDebugValue();
00086
00087 }
00088
00089 MarControlValueT<realvec>&
00090 MarControlValueT<realvec>::operator=(const MarControlValueT& a)
00091 {
00092 if (this != &a)
00093 {
00094 value_ = a.value_;
00095 type_ = a.type_;
00096
00097 setDebugValue();
00098
00099 }
00100 return *this;
00101 }
00102
00103 MarControlValue*
00104 MarControlValueT<realvec>::clone()
00105 {
00106 return new MarControlValueT<realvec>(*this);
00107 }
00108
00109 void
00110 MarControlValueT<realvec>::copyValue(MarControlValue& value)
00111 {
00112 MarControlValueT<realvec> &v = dynamic_cast<MarControlValueT<realvec>&>(value);
00113 value_ = v.value_;
00114 }
00115
00116 void
00117 MarControlValueT<realvec>::callMarSystemsUpdate()
00118 {
00119
00120
00121
00122
00123
00124
00125 tempValue_ = value_;
00126
00127
00128
00129 for(lit_ = links_.begin(); lit_ != links_.end(); ++lit_)
00130 {
00131 value_ = tempValue_;
00132 lit_->first->callMarSystemUpdate();
00133 }
00134 }
00135
00136 MarControlValue*
00137 MarControlValueT<realvec>::create()
00138 {
00139 return new MarControlValueT<realvec>(realvec());
00140 }
00141
00142 const realvec&
00143 MarControlValueT<realvec>::get() const
00144 {
00145 return value_;
00146 }
00147
00148 realvec&
00149 MarControlValueT<realvec>::getRef()
00150 {
00151 return value_;
00152 }
00153
00154 bool
00155 MarControlValueT<realvec>::isNotEqual(MarControlValue *v)
00156 {
00157 if(this != v)
00158 {
00159 if (type_ != "mrs_realvec")
00160 {
00161 MRSWARN("MarControlValueT::isNotEqual() - Types of MarControlValue are different");
00162 }
00163 return (value_ != dynamic_cast<MarControlValueT<realvec>*>(v)->get());
00164 }
00165 else
00166 return false;
00167 }
00168
00169 void
00170 MarControlValueT<realvec>::createFromStream(std::istream& in)
00171 {
00172 in >> value_;
00173
00174 setDebugValue();
00175 }
00176
00177 std::ostream&
00178 MarControlValueT<realvec>::serialize(std::ostream& os)
00179 {
00180 os << value_;
00181 return os;
00182 }
00183
00184 MarControlValue*
00185 MarControlValueT<realvec>::sum(MarControlValue *v)
00186 {
00187 (void) v;
00188 MRSASSERT(0);
00189 return 0;
00190 }
00191
00192 MarControlValue*
00193 MarControlValueT<realvec>::subtract(MarControlValue *v)
00194 {
00195 (void) v;
00196 MRSASSERT(0);
00197 return 0;
00198 }
00199
00200 MarControlValue*
00201 MarControlValueT<realvec>::multiply(MarControlValue *v)
00202 {
00203 (void) v;
00204 MRSASSERT(0);
00205 return 0;
00206 }
00207
00208 MarControlValue*
00209 MarControlValueT<realvec>::divide(MarControlValue *v)
00210 {
00211 (void) v;
00212 MRSASSERT(0);
00213 return 0;
00214 }
00215
00216
00217
00218
00219 bool MarControlValueT<bool>::invalidValue;
00220
00221
00222 MarControlValueT<bool>::MarControlValueT(bool value)
00223 {
00224 value_ = value;
00225 type_ = "mrs_bool";
00226
00227
00228 setDebugValue();
00229
00230
00231 }
00232
00233 MarControlValueT<bool>::MarControlValueT(const MarControlValueT& a):MarControlValue(a)
00234 {
00235 value_ = a.value_;
00236 type_ = "mrs_bool";
00237
00238 setDebugValue();
00239 }
00240
00241 MarControlValueT<bool>&
00242 MarControlValueT<bool>::operator=(const MarControlValueT& a)
00243 {
00244 if (this != &a)
00245 {
00246 value_ = a.value_;
00247 type_ = a.type_;
00248
00249 setDebugValue();
00250
00251 }
00252 return *this;
00253 }
00254
00255 MarControlValue*
00256 MarControlValueT<bool>::clone()
00257 {
00258 return new MarControlValueT<bool>(*this);
00259 }
00260
00261 void
00262 MarControlValueT<bool>::copyValue(MarControlValue& value)
00263 {
00264 MarControlValueT<bool> &v = dynamic_cast<MarControlValueT<bool>&>(value);
00265 value_ = v.value_;
00266 }
00267
00268 void
00269 MarControlValueT<bool>::callMarSystemsUpdate()
00270 {
00271
00272
00273
00274
00275
00276
00277 tempValue_ = value_;
00278
00279
00280
00281 for(lit_ = links_.begin(); lit_ != links_.end(); ++lit_)
00282 {
00283 value_ = tempValue_;
00284 lit_->first->callMarSystemUpdate();
00285 }
00286 }
00287
00288 MarControlValue*
00289 MarControlValueT<bool>::create()
00290 {
00291 return new MarControlValueT<bool>(false);
00292 }
00293
00294 const bool&
00295 MarControlValueT<bool>::get() const
00296 {
00297 return value_;
00298 }
00299
00300 void
00301 MarControlValueT<bool>::createFromStream(std::istream& in)
00302 {
00303 in >> value_;
00304
00305 setDebugValue();
00306 }
00307
00308 bool
00309 MarControlValueT<bool>::isNotEqual(MarControlValue *v)
00310 {
00311 if(this != v)
00312 {
00313 return (value_ != dynamic_cast<MarControlValueT<bool>*>(v)->get());
00314 }
00315 else
00316 return false;
00317 }
00318
00319 std::ostream&
00320 MarControlValueT<bool>::serialize(std::ostream& os)
00321 {
00322 os << value_;
00323 return os;
00324 }
00325
00326 MarControlValue*
00327 MarControlValueT<bool>::sum(MarControlValue *v)
00328 {
00329 (void) v;
00330 MRSASSERT(0);
00331 return 0;
00332 }
00333
00334 MarControlValue*
00335 MarControlValueT<bool>::subtract(MarControlValue *v)
00336 {
00337 (void) v;
00338 MRSASSERT(0);
00339 return 0;
00340 }
00341
00342 MarControlValue*
00343 MarControlValueT<bool>::multiply(MarControlValue *v)
00344 {
00345 (void) v;
00346 MRSASSERT(0);
00347 return 0;
00348 }
00349
00350 MarControlValue*
00351 MarControlValueT<bool>::divide(MarControlValue *v)
00352 {
00353 (void) v;
00354 MRSASSERT(0);
00355 return 0;
00356 }