-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//******************************************************************************* | ||
// ZX Tape Reviver | ||
//----------------- | ||
// | ||
// Author: Leonid Golouz | ||
// E-mail: [email protected] | ||
// YouTube channel: https://www.youtube.com/channel/UCz_ktTqWVekT0P4zVW8Xgcg | ||
// YouTube channel e-mail: [email protected] | ||
// | ||
// Code modification and distribution of any kind is not allowed without direct | ||
// permission of the Author. | ||
//******************************************************************************* | ||
|
||
#include "actionbase.h" | ||
|
||
ActionBase::ActionBase(int channel, const QString& name) : | ||
m_channel(channel), | ||
m_actionName(name) | ||
{ | ||
|
||
} | ||
|
||
int ActionBase::channel() const { | ||
return m_channel; | ||
} | ||
|
||
const QString& ActionBase::actionName() const { | ||
return m_actionName; | ||
} | ||
|
||
bool ActionBase::isActionValid(const QSharedPointer<QWavVector>& wf) const { | ||
return !wf.isNull(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//******************************************************************************* | ||
// ZX Tape Reviver | ||
//----------------- | ||
// | ||
// Author: Leonid Golouz | ||
// E-mail: [email protected] | ||
// YouTube channel: https://www.youtube.com/channel/UCz_ktTqWVekT0P4zVW8Xgcg | ||
// YouTube channel e-mail: [email protected] | ||
// | ||
// Code modification and distribution of any kind is not allowed without direct | ||
// permission of the Author. | ||
//******************************************************************************* | ||
|
||
#ifndef ACTIONBASE_H | ||
#define ACTIONBASE_H | ||
|
||
#include "sources/defines.h" | ||
#include <QString> | ||
#include <QSharedPointer> | ||
|
||
class ActionBase | ||
{ | ||
const int m_channel; | ||
const QString m_actionName; | ||
|
||
public: | ||
ActionBase(int channel, const QString& name = { }); | ||
virtual ~ActionBase() = default; | ||
|
||
int channel() const; | ||
const QString& actionName() const; | ||
|
||
virtual bool apply() = 0; | ||
virtual void undo() = 0; | ||
|
||
protected: | ||
virtual bool isActionValid(const QSharedPointer<QWavVector>& wf) const; | ||
}; | ||
|
||
#endif // ACTIONBASE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//******************************************************************************* | ||
// ZX Tape Reviver | ||
//----------------- | ||
// | ||
// Author: Leonid Golouz | ||
// E-mail: [email protected] | ||
// YouTube channel: https://www.youtube.com/channel/UCz_ktTqWVekT0P4zVW8Xgcg | ||
// YouTube channel e-mail: [email protected] | ||
// | ||
// Code modification and distribution of any kind is not allowed without direct | ||
// permission of the Author. | ||
//******************************************************************************* | ||
|
||
#include "editsampleaction.h" | ||
#include "sources/models/waveformmodel.h" | ||
#include "sources/translations/translations.h" | ||
|
||
EditSampleAction::EditSampleAction(int channel, const EditSampleActionParams& params) : | ||
ActionBase(channel, qtTrId(ID_EDIT_ACTION)), | ||
m_params(params) | ||
{ | ||
|
||
} | ||
|
||
bool EditSampleAction::apply() { | ||
auto wf { WaveFormModel::instance()->getChannel(channel()) }; | ||
const bool valid { isActionValid(wf) }; | ||
if (valid) { | ||
wf->operator[](m_params.sample) = m_params.newValue; | ||
} | ||
|
||
return valid; | ||
} | ||
|
||
void EditSampleAction::undo() { | ||
auto wf { WaveFormModel::instance()->getChannel(channel()) }; | ||
wf->operator[](m_params.sample) = m_params.previousValue; | ||
} | ||
|
||
bool EditSampleAction::isActionValid(const QSharedPointer<QWavVector>& wf) const { | ||
return ActionBase::isActionValid(wf) && m_params.sample >= 0 && m_params.sample < wf->size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//******************************************************************************* | ||
// ZX Tape Reviver | ||
//----------------- | ||
// | ||
// Author: Leonid Golouz | ||
// E-mail: [email protected] | ||
// YouTube channel: https://www.youtube.com/channel/UCz_ktTqWVekT0P4zVW8Xgcg | ||
// YouTube channel e-mail: [email protected] | ||
// | ||
// Code modification and distribution of any kind is not allowed without direct | ||
// permission of the Author. | ||
//******************************************************************************* | ||
|
||
#ifndef EDITSAMPLEACTION_H | ||
#define EDITSAMPLEACTION_H | ||
|
||
#include "actionbase.h" | ||
|
||
struct EditSampleActionParams { | ||
QWavVectorType previousValue; | ||
QWavVectorType newValue; | ||
int sample; | ||
}; | ||
|
||
class EditSampleAction : public ActionBase | ||
{ | ||
const EditSampleActionParams m_params; | ||
|
||
public: | ||
EditSampleAction(int channel, const EditSampleActionParams& params); | ||
virtual ~EditSampleAction() = default; | ||
|
||
virtual bool apply() override; | ||
virtual void undo() override; | ||
|
||
private: | ||
virtual bool isActionValid(const QSharedPointer<QWavVector>& wf) const; | ||
}; | ||
|
||
#endif // EDITSAMPLEACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//******************************************************************************* | ||
// ZX Tape Reviver | ||
//----------------- | ||
// | ||
// Author: Leonid Golouz | ||
// E-mail: [email protected] | ||
// YouTube channel: https://www.youtube.com/channel/UCz_ktTqWVekT0P4zVW8Xgcg | ||
// YouTube channel e-mail: [email protected] | ||
// | ||
// Code modification and distribution of any kind is not allowed without direct | ||
// permission of the Author. | ||
//******************************************************************************* | ||
|
||
#include "shiftwaveformaction.h" | ||
#include "sources/models/waveformmodel.h" | ||
#include "sources/translations/translations.h" | ||
|
||
ShiftWaveFormAction::ShiftWaveFormAction(int channel, const ShiftWaveFormActionParams& params) : | ||
ActionBase(channel, qtTrId(ID_SHIFT_WAVEFORM_ACTION)), | ||
m_params(params) | ||
{ | ||
|
||
} | ||
|
||
bool ShiftWaveFormAction::apply() { | ||
auto wf { WaveFormModel::instance()->getChannel(channel()) }; | ||
const bool valid { isActionValid(wf) }; | ||
if (valid) { | ||
std::for_each(wf->begin(), wf->end(), [this](QWavVectorType& itm) { | ||
itm += m_params.offsetValue; | ||
}); | ||
} | ||
return valid; | ||
} | ||
|
||
void ShiftWaveFormAction::undo() { | ||
auto wf { WaveFormModel::instance()->getChannel(channel()) }; | ||
std::for_each(wf->begin(), wf->end(), [this](QWavVectorType& itm) { | ||
itm -= m_params.offsetValue; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//******************************************************************************* | ||
// ZX Tape Reviver | ||
//----------------- | ||
// | ||
// Author: Leonid Golouz | ||
// E-mail: [email protected] | ||
// YouTube channel: https://www.youtube.com/channel/UCz_ktTqWVekT0P4zVW8Xgcg | ||
// YouTube channel e-mail: [email protected] | ||
// | ||
// Code modification and distribution of any kind is not allowed without direct | ||
// permission of the Author. | ||
//******************************************************************************* | ||
|
||
#ifndef SHIFTWAVEFORMACTION_H | ||
#define SHIFTWAVEFORMACTION_H | ||
|
||
#include "actionbase.h" | ||
|
||
struct ShiftWaveFormActionParams { | ||
QWavVectorType offsetValue; | ||
}; | ||
|
||
class ShiftWaveFormAction : public ActionBase | ||
{ | ||
const ShiftWaveFormActionParams m_params; | ||
|
||
public: | ||
ShiftWaveFormAction(int channel, const ShiftWaveFormActionParams& params); | ||
virtual ~ShiftWaveFormAction() = default; | ||
|
||
virtual bool apply() override; | ||
virtual void undo() override; | ||
}; | ||
|
||
#endif // SHIFTWAVEFORMACTION_H |