1 /*
2 * Copyright (C) 2018-2020 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 "set_key_on_to_step_command.hpp"
27
SetKeyOnToStepCommand(std::weak_ptr<Module> mod,int songNum,int trackNum,int orderNum,int stepNum,int noteNum,bool instMask,int instNum,bool volMask,int vol,bool isFMReversed)28 SetKeyOnToStepCommand::SetKeyOnToStepCommand(std::weak_ptr<Module> mod, int songNum, int trackNum, int orderNum,
29 int stepNum, int noteNum, bool instMask, int instNum, bool volMask, int vol, bool isFMReversed)
30 : mod_(mod),
31 song_(songNum),
32 track_(trackNum),
33 order_(orderNum),
34 step_(stepNum),
35 note_(noteNum),
36 inst_(instNum),
37 vol_(vol),
38 instMask_(instMask),
39 volMask_(volMask),
40 isFMReserved_(isFMReversed)
41 {
42 auto& st = mod_.lock()->getSong(songNum).getTrack(trackNum).getPatternFromOrderNumber(orderNum).getStep(stepNum);
43 prevNote_ = st.getNoteNumber();
44 if (!instMask) prevInst_ = st.getInstrumentNumber();
45 if (!volMask) prevVol_ = st.getVolume();
46 }
47
redo()48 void SetKeyOnToStepCommand::redo()
49 {
50 auto& st = mod_.lock()->getSong(song_).getTrack(track_).getPatternFromOrderNumber(order_).getStep(step_);
51 st.setNoteNumber(note_);
52 if (!instMask_) st.setInstrumentNumber(inst_);
53 if (!volMask_) st.setVolume((isFMReserved_ && vol_ < 0x80) ? (0x7f - vol_) : vol_);
54 }
55
undo()56 void SetKeyOnToStepCommand::undo()
57 {
58 auto& st = mod_.lock()->getSong(song_).getTrack(track_).getPatternFromOrderNumber(order_).getStep(step_);
59 st.setNoteNumber(prevNote_);
60 if (!instMask_) st.setInstrumentNumber(prevInst_);
61 if (!volMask_) st.setVolume(prevVol_);
62 }
63
getID() const64 CommandId SetKeyOnToStepCommand::getID() const
65 {
66 return CommandId::SetKeyOnToStep;
67 }
68