Debian Codegraph @

BambooTracker/command/pattern/paste_copied_data_to_pattern_command.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2018 Rerrah
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "paste_copied_data_to_pattern_command.hpp"
7 #include "pattern_command_utils.hpp"
8
9 PasteCopiedDataToPatternCommand::PasteCopiedDataToPatternCommand(
10 std::weak_ptr<Module> mod, int songNum, int beginTrack, int beginColmn,
11 int beginOrder, int beginStep, const Vector2d<std::string>& cells)
12 : AbstractCommand(CommandId::PasteCopiedDataToPattern),
13 mod_(mod),
14 song_(songNum),
15 track_(beginTrack),
16 col_(beginColmn),
17 order_(beginOrder),
18 step_(beginStep),
19 cells_(cells)
20 {
21 auto& song = mod.lock()->getSong(songNum);
22 prevCells_ = command_utils::getPreviousCells(song, cells.columnSize(), cells.rowSize(),
23 beginTrack, beginColmn, beginOrder, beginStep);
24 }
25
26 bool PasteCopiedDataToPatternCommand::redo()
27 {
28 try {
29 command_utils::restorePattern(mod_.lock()->getSong(song_), cells_, track_, col_, order_, step_);
30 return true;
31 }
32 catch (...) {
33 return false;
34 }
35 }
36
37 bool PasteCopiedDataToPatternCommand::undo()
38 {
39 try {
40 command_utils::restorePattern(mod_.lock()->getSong(song_), prevCells_, track_, col_, order_, step_);
41 return true;
42 }
43 catch (...) {
44 return false;
45 }
46 }