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