Debian Codegraph @

BambooTracker/command/pattern/set_effect_id_to_step_command.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2018 Rerrah
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "set_effect_id_to_step_command.hpp"
7 #include "pattern_command_utils.hpp"
8
9 SetEffectIDToStepCommand::SetEffectIDToStepCommand(
10 std::weak_ptr<Module> mod, int songNum, int trackNum, int orderNum, int stepNum,
11 int n, std::string id, bool fillValue00, bool secondEntry)
12 : AbstractCommand(CommandId::SetEffectIDToStep),
13 mod_(mod),
14 song_(songNum),
15 track_(trackNum),
16 order_(orderNum),
17 step_(stepNum),
18 n_(n),
19 effID_(id),
20 isSecondEntry_(secondEntry)
21 {
22 Step& step = command_utils::getStep(mod, songNum, trackNum, orderNum, stepNum);
23 prevEffID_ = step.getEffectId(n);
24 filledValue00_ = fillValue00 && !step.hasEffectValue(n);
25 }
26
27 bool SetEffectIDToStepCommand::redo()
28 {
29 std::string str = isSecondEntry_ ? effID_ : ("0" + effID_);
30 Step& step = command_utils::getStep(mod_, song_, track_, order_, step_);
31 step.setEffectId(n_, str);
32 if (filledValue00_) step.setEffectValue(n_, 0);
33 return true;
34 }
35
36 bool SetEffectIDToStepCommand::undo()
37 {
38 Step& step = command_utils::getStep(mod_, song_, track_, order_, step_);
39 step.setEffectId(n_, prevEffID_);
40 if (filledValue00_) step.clearEffectValue(n_);
41
42 if (!isSecondEntry_) { // Forced complete
43 effID_ = "0" + effID_;
44 isSecondEntry_ = true;
45 }
46 return true;
47 }
48
49 bool SetEffectIDToStepCommand::mergeWith(const AbstractCommand* other)
50 {
51 if (other->getID() == getID() && !isSecondEntry_) {
52 auto com = dynamic_cast<const SetEffectIDToStepCommand*>(other);
53 if (com->song_ == song_ && com->track_ == track_
54 && com->order_ == order_ && com->step_ == step_ && com->n_ == n_
55 && com->isSecondEntry_) {
56 effID_ = effID_ + com->effID_;
57 isSecondEntry_ = true;
58 redo();
59 return true;
60 }
61 }
62
63 // Enterd only 1 character
64 if (!isSecondEntry_) {
65 effID_ = "0" + effID_;
66 isSecondEntry_ = true;
67 }
68
69 return false;
70 }