Debian Codegraph @

BambooTracker/instrument/envelope_fm.cpp

raw
1 /*
2 * Copyright (C) 2018-2021 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 "envelope_fm.hpp"
27
28 namespace
29 {
30 const std::unordered_map<FMEnvelopeParameter, int> DEF_PARAMS = {
31 { FMEnvelopeParameter::AL, 4 },
32 { FMEnvelopeParameter::FB, 0 },
33 { FMEnvelopeParameter::AR1, 31 },
34 { FMEnvelopeParameter::DR1, 0 },
35 { FMEnvelopeParameter::SR1, 0 },
36 { FMEnvelopeParameter::RR1, 7 },
37 { FMEnvelopeParameter::SL1, 0 },
38 { FMEnvelopeParameter::TL1, 32 },
39 { FMEnvelopeParameter::KS1, 0 },
40 { FMEnvelopeParameter::ML1, 0 },
41 { FMEnvelopeParameter::DT1, 0 },
42 { FMEnvelopeParameter::SSGEG1, -1 },
43 { FMEnvelopeParameter::AR2, 31 },
44 { FMEnvelopeParameter::DR2, 0 },
45 { FMEnvelopeParameter::SR2, 0 },
46 { FMEnvelopeParameter::RR2, 7 },
47 { FMEnvelopeParameter::SL2, 0 },
48 { FMEnvelopeParameter::TL2, 0 },
49 { FMEnvelopeParameter::KS2, 0 },
50 { FMEnvelopeParameter::ML2, 0 },
51 { FMEnvelopeParameter::DT2, 0 },
52 { FMEnvelopeParameter::SSGEG2, -1 },
53 { FMEnvelopeParameter::AR3, 31 },
54 { FMEnvelopeParameter::DR3, 0 },
55 { FMEnvelopeParameter::SR3, 0 },
56 { FMEnvelopeParameter::RR3, 7 },
57 { FMEnvelopeParameter::SL3, 0 },
58 { FMEnvelopeParameter::TL3, 32 },
59 { FMEnvelopeParameter::KS3, 0 },
60 { FMEnvelopeParameter::ML3, 0 },
61 { FMEnvelopeParameter::DT3, 0 },
62 { FMEnvelopeParameter::SSGEG3, -1 },
63 { FMEnvelopeParameter::AR4, 31 },
64 { FMEnvelopeParameter::DR4, 0 },
65 { FMEnvelopeParameter::SR4, 0 },
66 { FMEnvelopeParameter::RR4, 7 },
67 { FMEnvelopeParameter::SL4, 0 },
68 { FMEnvelopeParameter::TL4, 0 },
69 { FMEnvelopeParameter::KS4, 0 },
70 { FMEnvelopeParameter::ML4, 0 },
71 { FMEnvelopeParameter::DT4, 0 },
72 { FMEnvelopeParameter::SSGEG4, -1 }
73 };
74 }
75
76 EnvelopeFM::EnvelopeFM(int num)
77 : AbstractInstrumentProperty(num)
78 {
79 clearParameters();
80 }
81
82 std::unique_ptr<EnvelopeFM> EnvelopeFM::clone()
83 {
84 std::unique_ptr<EnvelopeFM> clone = std::make_unique<EnvelopeFM>(*this);
85 clone->clearUserInstruments();
86 return clone;
87 }
88
89 bool EnvelopeFM::getOperatorEnabled(int num) const
90 {
91 return isEnabledOp_.test(num);
92 }
93
94 void EnvelopeFM::setOperatorEnabled(int num, bool enabled)
95 {
96 isEnabledOp_.set(num, enabled);
97 }
98
99 int EnvelopeFM::getParameterValue(FMEnvelopeParameter param) const
100 {
101 return params_.at(param);
102 }
103
104 void EnvelopeFM::setParameterValue(FMEnvelopeParameter param, int value)
105 {
106 params_.at(param) = value;
107 }
108
109 bool EnvelopeFM::isEdited() const
110 {
111 return (params_ != DEF_PARAMS || !isEnabledOp_.all());
112 }
113
114 void EnvelopeFM::clearParameters()
115 {
116 params_ = DEF_PARAMS;
117 isEnabledOp_.set();
118 }