Debian Codegraph @

BambooTracker/command/pattern/set_instrument_to_step_command.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2018 Rerrah
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "set_instrument_to_step_command.hpp"
7 #include "pattern_command_utils.hpp"
8
9 SetInstrumentToStepCommand::SetInstrumentToStepCommand(
10 std::weak_ptr<Module> mod, int songNum, int trackNum, int orderNum,
11 int stepNum, int instNum, bool secondEntry)
12 : AbstractCommand(CommandId::SetInstrumentInStep),
13 mod_(mod),
14 song_(songNum),
15 track_(trackNum),
16 order_(orderNum),
17 step_(stepNum),
18 inst_(instNum),
19 prevInst_(command_utils::getStep(mod, songNum, trackNum, orderNum, stepNum).getInstrumentNumber()),
20 isSecondEntry_(secondEntry)
21 {
22 }
23
24 bool SetInstrumentToStepCommand::redo()
25 {
26 command_utils::getStep(mod_, song_, track_, order_, step_).setInstrumentNumber(inst_);
27 return true;
28 }
29
30 bool SetInstrumentToStepCommand::undo()
31 {
32 command_utils::getStep(mod_, song_, track_, order_, step_).setInstrumentNumber(prevInst_);
33 isSecondEntry_ = true; // Forced complete
34 return true;
35 }
36
37 bool SetInstrumentToStepCommand::mergeWith(const AbstractCommand* other)
38 {
39 if (other->getID() == getID() && !isSecondEntry_) {
40 auto com = dynamic_cast<const SetInstrumentToStepCommand*>(other);
41 if (com->song_ == song_ && com->track_ == track_
42 && com->order_ == order_ && com->step_ == step_
43 && com->isSecondEntry_) {
44 inst_ = (inst_ << 4) + com->inst_;
45 redo();
46 isSecondEntry_ = true;
47 return true;
48 }
49 }
50
51 isSecondEntry_ = true;
52 return false;
53 }