Skip to content

Commit

Permalink
[scenario] Create an interactive dot when double-clicking in the back…
Browse files Browse the repository at this point in the history
…ground of the score
  • Loading branch information
jcelerier committed Oct 27, 2024
1 parent b3a3096 commit 32a0bac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@ class CreateStateMacro final : public score::AggregateCommand
SCORE_COMMAND_DECL(CommandFactoryName(), CreateStateMacro, "Drop a state")
public:
};

/**
* @brief The CreateDot class
*
* Used to create a dot by double clicking
*
*/
class CreateDot final : public score::AggregateCommand
{
SCORE_COMMAND_DECL(CommandFactoryName(), CreateDot, "Create a dot")
public:
};
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +0,0 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "SetAutoTrigger.hpp"

#include <Scenario/Document/TimeSync/TimeSyncModel.hpp>

#include <score/model/path/PathSerialization.hpp>

namespace Scenario
{
namespace Command
{

SetAutoTrigger::SetAutoTrigger(const TimeSyncModel& tn, bool b)
: m_path{std::move(tn)}
, m_old{tn.autotrigger()}
, m_new{b}
{
}

void SetAutoTrigger::undo(const score::DocumentContext& ctx) const
{
auto& tn = m_path.find(ctx);
tn.setAutotrigger(m_old);
}

void SetAutoTrigger::redo(const score::DocumentContext& ctx) const
{
auto& tn = m_path.find(ctx);
tn.setAutotrigger(m_new);
}

void SetAutoTrigger::serializeImpl(DataStreamInput& s) const
{
s << m_path << m_old << m_new;
}

void SetAutoTrigger::deserializeImpl(DataStreamOutput& s)
{
s >> m_path >> m_old >> m_new;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,26 @@
#include <score/command/PropertyCommand.hpp>
#include <score/model/path/Path.hpp>

namespace Scenario
namespace Scenario::Command
{
class TimeSyncModel;
namespace Command
{
using TimeSyncModel = ::Scenario::TimeSyncModel;
class SCORE_PLUGIN_SCENARIO_EXPORT SetAutoTrigger final : public score::Command
{
SCORE_COMMAND_DECL(CommandFactoryName(), SetAutoTrigger, "Change a trigger")
public:
SetAutoTrigger(const TimeSyncModel& tn, bool t);

void undo(const score::DocumentContext& ctx) const override;
void redo(const score::DocumentContext& ctx) const override;

protected:
void serializeImpl(DataStreamInput&) const override;
void deserializeImpl(DataStreamOutput&) override;

private:
Path<TimeSyncModel> m_path;
bool m_old{}, m_new{};
};
using TimeSyncModel = Scenario::TimeSyncModel;

}
}

PROPERTY_COMMAND_T(
Scenario::Command, SetTimeSyncMusicalSync, TimeSyncModel::p_musicalSync, "Set sync")
SCORE_COMMAND_DECL_T(Scenario::Command::SetTimeSyncMusicalSync)

PROPERTY_COMMAND_T(
Scenario::Command, SetTimeSyncIsActive, TimeSyncModel::p_active, "Set active")
SCORE_COMMAND_DECL_T(Scenario::Command::SetTimeSyncActive)

PROPERTY_COMMAND_T(
Scenario::Command, SetTimeSyncIsStartPoint, TimeSyncModel::p_startPoint,
"Set start point")
SCORE_COMMAND_DECL_T(Scenario::Command::SetTimeSyncIsStartPoint)

PROPERTY_COMMAND_T(
Scenario::Command, SetTimeSyncIsAutoTrigger, TimeSyncModel::p_autotrigger,
"Set auto-trigger")
SCORE_COMMAND_DECL_T(Scenario::Command::SetTimeSyncIsAutoTrigger)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <score_plugin_scenario_export.h>

#include <chrono>
#include <verdigris>
class DataStream;
class JSONObject;
Expand Down Expand Up @@ -110,8 +109,14 @@ class SCORE_PLUGIN_SCENARIO_EXPORT TimeSyncModel final
PROPERTY(
ossia::musical_sync,
musicalSync READ musicalSync WRITE setMusicalSync NOTIFY musicalSyncChanged)
PROPERTY(bool, active READ active WRITE setActive NOTIFY activeChanged)
PROPERTY(
bool, autotrigger READ autotrigger WRITE setAutotrigger NOTIFY autotriggerChanged)
PROPERTY(
bool, startPoint READ isStartPoint WRITE setStartPoint NOTIFY startPointChanged)
PROPERTY(
State::Expression,
expression READ expression WRITE setExpression NOTIFY triggerChanged)

private:
TimeVal m_date{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ to the root of a score.)_"));
m_btnLayout.addWidget(m_autotrigger);
connect(m_autotrigger, &QAbstractButton::toggled, this, [&](bool t) {
if(t != object.autotrigger())
CommandDispatcher<>{ctx.commandStack}.submit<Scenario::Command::SetAutoTrigger>(
object, t);
CommandDispatcher<>{ctx.commandStack}
.submit<Scenario::Command::SetTimeSyncIsAutoTrigger>(object, t);
});
connect(&object, &TimeSyncModel::autotriggerChanged, this, [&](bool t) {
if(t != m_autotrigger->isDown())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
#include <Scenario/Application/Menus/ScenarioCopy.hpp>
#include <Scenario/Application/ScenarioActions.hpp>
#include <Scenario/Application/ScenarioApplicationPlugin.hpp>
#include <Scenario/Commands/CommandAPI.hpp>
#include <Scenario/Commands/Comment/SetCommentText.hpp>
#include <Scenario/Commands/Scenario/Creations/CreateCommentBlock.hpp>
#include <Scenario/Commands/Scenario/Creations/CreateInterval_State_Event_TimeSync.hpp>
#include <Scenario/Commands/Scenario/Creations/CreateStateMacro.hpp>
#include <Scenario/Commands/Scenario/Creations/CreateTimeSync_Event_State.hpp>
#include <Scenario/Commands/Scenario/Displacement/MoveCommentBlock.hpp>
#include <Scenario/Commands/TimeSync/SetAutoTrigger.hpp>
#include <Scenario/Document/Interval/Graph/GraphIntervalPresenter.hpp>
#include <Scenario/Document/State/ItemModel/MessageItemModel.hpp>
#include <Scenario/Process/ScenarioView.hpp>
Expand Down Expand Up @@ -757,9 +760,13 @@ void ScenarioPresenter::doubleClick(QPointF pt)

auto sp = toScenarioPoint(pt);

// Just create a dot
auto cmd = new Command::CreateTimeSync_Event_State{model(), sp.date, sp.y};
CommandDispatcher<>{m_context.context.commandStack}.submit(cmd);
Scenario::Command::Macro m{new Scenario::Command::CreateDot, m_context.context};
auto [ts, ev, s] = m.createDot(model(), sp);

m.setProperty<TimeSyncModel::p_startPoint>(ts, true);
m.setProperty<TimeSyncModel::p_active>(ts, true);

m.commit();
}

void ScenarioPresenter::on_focusChanged()
Expand Down

0 comments on commit 32a0bac

Please sign in to comment.