summaryrefslogtreecommitdiff
path: root/src/channelmixer.cc
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-03-29 10:43:00 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2016-03-31 17:35:47 +0200
commit90cf32becc608fdd1a5e9bf815e040d7fb71b819 (patch)
tree4be9aab027935957466271f2ea760e9d8fb1b782 /src/channelmixer.cc
parentfa677c584b698d4d8aa8acc967f31960a01a9cf6 (diff)
refactored class ChannelMixer
Diffstat (limited to 'src/channelmixer.cc')
-rw-r--r--src/channelmixer.cc95
1 files changed, 50 insertions, 45 deletions
diff --git a/src/channelmixer.cc b/src/channelmixer.cc
index 76a25a6..510d9a8 100644
--- a/src/channelmixer.cc
+++ b/src/channelmixer.cc
@@ -26,40 +26,46 @@
*/
#include "channelmixer.h"
-ChannelMixer::ChannelMixer(Channels &c, Channel *defc, float defg)
- : channels(c)
+ChannelMixer::ChannelMixer(const Channels& c, const Channel* defc, float defg)
+ : mix{}
+ , defaultchannel{nullptr}
+ , defaultgain{1.f}
+ , channels(c)
{
- setDefaults(defc, defg);
+ setDefaults(defc, defg);
}
-void ChannelMixer::setDefaults(Channel *defc, float defg)
+void ChannelMixer::setDefaults(const Channel* defc, float defg)
{
- defaultchannel = defc;
- if(defc == NULL && channels.size() > 0) defaultchannel = &channels[0];
+ defaultchannel = defc;
+ if(defc == nullptr && channels.size() > 0)
+ {
+ defaultchannel = &channels[0];
+ }
- defaultgain = defg;
+ defaultgain = defg;
}
-MixerSettings &ChannelMixer::lookup(InstrumentChannel *c)
+MixerSettings& ChannelMixer::lookup(const InstrumentChannel& c)
{
- std::map<InstrumentChannel *, MixerSettings>::iterator mi = mix.find(c);
-
- if(mi == mix.end()) {
- MixerSettings m;
- m.gain = defaultgain;
- m.output = defaultchannel;
- mix[c] = m;
- return mix[c];
- }
-
- return mi->second;
+ auto mi = mix.find(&c);
+
+ if(mi == mix.end())
+ {
+ MixerSettings m;
+ m.gain = defaultgain;
+ m.output = defaultchannel;
+ mix[&c] = m;
+ return mix[&c];
+ }
+
+ return mi->second;
}
-
#ifdef TEST_CHANNELMIXER
-//deps: channel.cc
-//cflags:
-//libs:
+// deps: channel.cc
+// cflags:
+// libs:
#include "test.h"
TEST_BEGIN;
@@ -71,40 +77,39 @@ channels.push_back(ch1);
channels.push_back(ch2);
{
- ChannelMixer mixer(channels, NULL, 1.0);
+ ChannelMixer mixer(channels, nullptr, 1.0);
- InstrumentChannel ich;
- MixerSettings &m = mixer.lookup(&ich);
- TEST_EQUAL(m.output, &channels[0], "Default channel?");
- TEST_EQUAL_FLOAT(m.gain, 1.0, "Default gain?");
+ InstrumentChannel ich;
+ MixerSettings& m = mixer.lookup(&ich);
+ TEST_EQUAL(m.output, &channels[0], "Default channel?");
+ TEST_EQUAL_FLOAT(m.gain, 1.0, "Default gain?");
}
{
- ChannelMixer mixer(channels, &channels[1]);
+ ChannelMixer mixer(channels, &channels[1]);
- InstrumentChannel ich;
- MixerSettings &m = mixer.lookup(&ich);
- TEST_EQUAL(m.output, &channels[1], "Default channel?");
- TEST_EQUAL_FLOAT(m.gain, 1.0, "Default gain?");
+ InstrumentChannel ich;
+ MixerSettings& m = mixer.lookup(&ich);
+ TEST_EQUAL(m.output, &channels[1], "Default channel?");
+ TEST_EQUAL_FLOAT(m.gain, 1.0, "Default gain?");
}
{
- ChannelMixer mixer(channels, &channels[1]);
+ ChannelMixer mixer(channels, &channels[1]);
- InstrumentChannel ich;
- MixerSettings &m = mixer.lookup(&ich);
- TEST_EQUAL(m.output, &channels[1], "Default channel?");
- TEST_EQUAL_FLOAT(m.gain, 1.0, "Default gain?");
+ InstrumentChannel ich;
+ MixerSettings& m = mixer.lookup(&ich);
+ TEST_EQUAL(m.output, &channels[1], "Default channel?");
+ TEST_EQUAL_FLOAT(m.gain, 1.0, "Default gain?");
- m.output = &channels[0];
- m.gain = 0.5;
+ m.output = &channels[0];
+ m.gain = 0.5;
- MixerSettings &m2 = mixer.lookup(&ich);
- TEST_EQUAL(m2.output, &channels[0], "Changed channel?");
- TEST_EQUAL_FLOAT(m2.gain, 0.5, "Changed gain?");
+ MixerSettings& m2 = mixer.lookup(&ich);
+ TEST_EQUAL(m2.output, &channels[0], "Changed channel?");
+ TEST_EQUAL_FLOAT(m2.gain, 0.5, "Changed gain?");
}
-
TEST_END;
-#endif/*TEST_CHANNELMIXER*/
+#endif /*TEST_CHANNELMIXER*/