Debian Codegraph @

BambooTracker/command/pattern/set_effect_value_to_step_command.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2018 Rerrah
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "set_effect_value_to_step_command.hpp"
7 #include "pattern_command_utils.hpp"
8 #include "effect.hpp"
9
10 SetEffectValueToStepCommand::SetEffectValueToStepCommand(
11 std::weak_ptr<Module> mod, int songNum, int trackNum, int orderNum, int stepNum,
12 int n, int value, EffectDisplayControl ctrl, bool secondEntry)
13 : AbstractCommand(CommandId::SetEffectValueToStep),
14 mod_(mod),
15 song_(songNum),
16 track_(trackNum),
17 order_(orderNum),
18 step_(stepNum),
19 n_(n),
20 val_(value),
21 ctrl_(ctrl),
22 isSecondEntry_(secondEntry)
23 {
24 prevVal_ = command_utils::getStep(mod, songNum, trackNum, orderNum, stepNum).getEffectValue(n);
25 }
26
27 bool SetEffectValueToStepCommand::redo()
28 {
29 int value;
30 switch (ctrl_) {
31 default:
32 case EffectDisplayControl::Unset:
33 value = val_;
34 break;
35 case EffectDisplayControl::ReverseFMVolumeDelay:
36 value = effect_utils::reverseFmVolume(val_);
37 break;
38 case EffectDisplayControl::ReverseFMBrightness:
39 value = effect_utils::reverseFmBrightness(val_);
40 break;
41 }
42 command_utils::getStep(mod_, song_, track_, order_, step_).setEffectValue(n_, value);
43 return true;
44 }
45
46 bool SetEffectValueToStepCommand::undo()
47 {
48 command_utils::getStep(mod_, song_, track_, order_, step_).setEffectValue(n_, prevVal_);
49 isSecondEntry_ = true; // Forced complete
50 return true;
51 }
52
53 bool SetEffectValueToStepCommand::mergeWith(const AbstractCommand* other)
54 {
55 if (other->getID() == getID() && !isSecondEntry_) {
56 auto com = dynamic_cast<const SetEffectValueToStepCommand*>(other);
57 if (com->song_ == song_ && com->track_ == track_
58 && com->order_ == order_ && com->step_ == step_ && com->n_ == n_
59 && com->isSecondEntry_) {
60 val_ = (val_ << 4) + com->val_;
61 redo();
62 isSecondEntry_ = true;
63 return true;
64 }
65 }
66
67 isSecondEntry_ = true;
68 return false;
69 }