1 /*
2 * Copyright (C) 2018-2020 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "lfo_fm.hpp"
27 #include <stdexcept>
28
29 constexpr int LFOFM::DEF_AM_OP_[4];
30
LFOFM(int n)31 LFOFM::LFOFM(int n)
32 : AbstractInstrumentProperty (n)
33 {
34 clearParameters();
35 }
36
LFOFM(const LFOFM & other)37 LFOFM::LFOFM(const LFOFM& other)
38 : AbstractInstrumentProperty (other)
39 {
40 freq_ = other.freq_;
41 ams_ = other.ams_;
42 pms_ = other.pms_;
43 cnt_ = other.cnt_;
44 for (int i = 0; i < 4; ++i)
45 amOp_[i] = other.amOp_[i];
46 }
47
operator ==(const LFOFM & a,const LFOFM & b)48 bool operator==(const LFOFM& a, const LFOFM& b)
49 {
50 return (a.freq_ == b.freq_ && a.ams_ == b.ams_ && a.pms_ == b.pms_ && a.cnt_ == b.cnt_
51 && a.amOp_[0] == b.amOp_[0] && a.amOp_[1] == b.amOp_[1]
52 && a.amOp_[2] == b.amOp_[2] && a.amOp_[3] == b.amOp_[3]);
53 }
54
clone()55 std::unique_ptr<LFOFM> LFOFM::clone()
56 {
57 std::unique_ptr<LFOFM> clone = std::make_unique<LFOFM>(*this);
58 clone->clearUserInstruments();
59 return clone;
60 }
61
setParameterValue(FMLFOParameter param,int value)62 void LFOFM::setParameterValue(FMLFOParameter param, int value)
63 {
64 switch (param) {
65 case FMLFOParameter::FREQ: freq_ = value; break;
66 case FMLFOParameter::PMS: pms_ = value; break;
67 case FMLFOParameter::AMS: ams_ = value; break;
68 case FMLFOParameter::Count: cnt_ = value; break;
69 case FMLFOParameter::AM1: amOp_[0] = value; break;
70 case FMLFOParameter::AM2: amOp_[1] = value; break;
71 case FMLFOParameter::AM3: amOp_[2] = value; break;
72 case FMLFOParameter::AM4: amOp_[3] = value; break;
73 }
74 }
75
getParameterValue(FMLFOParameter param) const76 int LFOFM::getParameterValue(FMLFOParameter param) const
77 {
78 switch (param) {
79 case FMLFOParameter::FREQ: return freq_;
80 case FMLFOParameter::PMS: return pms_;
81 case FMLFOParameter::AMS: return ams_;
82 case FMLFOParameter::Count: return cnt_;
83 case FMLFOParameter::AM1: return amOp_[0];
84 case FMLFOParameter::AM2: return amOp_[1];
85 case FMLFOParameter::AM3: return amOp_[2];
86 case FMLFOParameter::AM4: return amOp_[3];
87 default: throw std::invalid_argument("Unexpected FMLFOParameter.");
88 }
89 }
90
isEdited() const91 bool LFOFM::isEdited() const
92 {
93 if (freq_ != DEF_FREQ_
94 || pms_ != DEF_PMS_
95 || ams_ != DEF_AMS_
96 || cnt_ != DEF_CNT_)
97 return true;
98 for (int i = 0; i < 4; ++i) {
99 if (amOp_[i] != DEF_AM_OP_[i]) return true;
100 }
101 return false;
102 }
103
clearParameters()104 void LFOFM::clearParameters()
105 {
106 freq_ = DEF_FREQ_;
107 pms_ = DEF_PMS_;
108 ams_ = DEF_AMS_;
109 cnt_ = DEF_CNT_;
110 for (int i = 0; i < 4; ++i) {
111 amOp_[i] = DEF_AM_OP_[i];
112 }
113 }
114