Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
change_parameter_value_command.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/parameter.h"
7
8#include <QUndoCommand>
9
10namespace zrythm::commands
11{
12class ChangeParameterValueCommand : public QUndoCommand
13{
14
15public:
16 ChangeParameterValueCommand (dsp::ProcessorParameter &param, float value)
17 : QUndoCommand (
18 QObject::tr ("Change '%1' value to %2").arg (param.label ()).arg (value)),
19 param_ (param), value_after_ (value)
20 {
21 }
22
23 int id () const override { return 89453187; }
24 bool mergeWith (const QUndoCommand * other) override
25 {
26 if (other->id () != id ())
27 return false;
28
29 // only merge if other command was made in quick succession of this
30 // command's redo()
31 const auto * other_cmd =
32 dynamic_cast<const ChangeParameterValueCommand *> (other);
33 const auto cur_time = std::chrono::steady_clock::now ();
34 const auto duration = cur_time - last_redo_timestamp_;
35 if (
36 std::chrono::duration_cast<std::chrono::milliseconds> (duration).count ()
37 > 1'000)
38 {
39 return false;
40 }
41
42 last_redo_timestamp_ = cur_time;
43 value_after_ = other_cmd->value_after_;
44 return true;
45 }
46
47 void undo () override { param_.setBaseValue (value_before_); }
48 void redo () override
49 {
50 value_before_ = param_.baseValue ();
51 param_.setBaseValue (value_after_);
52 last_redo_timestamp_ = std::chrono::steady_clock::now ();
53 }
54
55private:
57 float value_before_{};
58 float value_after_{};
59 std::chrono::time_point<std::chrono::steady_clock> last_redo_timestamp_;
60};
61
62} // namespace zrythm::commands
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
Definition parameter.h:225