File: scriptentry.h

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 214,188 kB
  • sloc: cpp: 291,198; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 244; perl: 82; pascal: 79
file content (127 lines) | stat: -rw-r--r-- 4,902 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2018 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#ifndef __SCRIPTENTRY_H__
#define __SCRIPTENTRY_H__

#include "libmscore/element.h"

namespace Ms {

struct InspectorItem;
class ScriptContext;

//---------------------------------------------------------
//   ScriptEntry
//---------------------------------------------------------

class ScriptEntry {
   protected:
      static constexpr const char* SCRIPT_INIT = "init";
      static constexpr const char* SCRIPT_CMD = "cmd";
      static constexpr const char* SCRIPT_PALETTE = "palette";
      static constexpr const char* SCRIPT_INSPECTOR = "inspector";
      static constexpr const char* SCRIPT_EXCERPT_CHANGE = "excerpt";
      static constexpr const char* SCRIPT_TEST = "test";

      static QString entryTemplate(const char* entryType) { return QString("%1 %2").arg(entryType); }

   public:
      virtual ~ScriptEntry() = default;
      virtual bool execute(ScriptContext& ctx) const = 0;
      virtual QString serialize() const = 0;
      static std::unique_ptr<ScriptEntry> deserialize(const QString& line);
      };

//---------------------------------------------------------
//   InitScriptEntry
//    Initializes the environment for the script.
//---------------------------------------------------------

class InitScriptEntry : public ScriptEntry {
      QString _filePath;
   public:
      explicit InitScriptEntry(const ScriptContext& ctx);
      explicit InitScriptEntry(const QString& filePath) : _filePath(filePath) {}
      bool execute(ScriptContext& ctx) const override;
      QString serialize() const override;
      static std::unique_ptr<ScriptEntry> deserialize(const QStringList& tokens);
      };

//---------------------------------------------------------
//   CommandScriptEntry
//---------------------------------------------------------

class CommandScriptEntry : public ScriptEntry {
      QByteArray _command;
   public:
      explicit CommandScriptEntry(const QByteArray& cmd) : _command(cmd) {}
      explicit CommandScriptEntry(const QString& cmd) : _command(cmd.toLatin1()) {}
      explicit CommandScriptEntry(const char* cmd) : _command(cmd) {}
      bool execute(ScriptContext& ctx) const override;
      QString serialize() const override { return entryTemplate(SCRIPT_CMD).arg(_command.constData()); };
      };

//---------------------------------------------------------
//   PaletteElementScriptEntry
//---------------------------------------------------------

class PaletteElementScriptEntry : public ScriptEntry {
      ElementType _type;
      std::vector<std::pair<Pid, QString>> _props;
      static const std::initializer_list<Pid> _pids;

      PaletteElementScriptEntry(ElementType type, std::vector<std::pair<Pid, QString>>&& props) : _type(type), _props(props) {}

   public:
      bool execute(ScriptContext& ctx) const override;
      static std::unique_ptr<ScriptEntry> fromContext(const Element* e, ScriptContext& ctx);
      QString serialize() const override;
      static std::unique_ptr<ScriptEntry> deserialize(const QStringList& tokens);
      };

//---------------------------------------------------------
//   InspectorScriptEntry
//---------------------------------------------------------

class InspectorScriptEntry : public ScriptEntry {
      ElementType _type;
      int _parentLevel;
      Pid _pid;
      QVariant _val;

   public:
      InspectorScriptEntry(ElementType type, int parentLevel, Pid pid, QVariant value)
         : _type(type), _parentLevel(parentLevel), _pid(pid), _val(std::move(value)) {}
      bool execute(ScriptContext& ctx) const override;
      QString serialize() const override;
      static std::unique_ptr<ScriptEntry> fromContext(const Element*, const InspectorItem&, const QVariant&);
      static std::unique_ptr<ScriptEntry> deserialize(const QStringList& tokens);
      };

//---------------------------------------------------------
//   ExcerptChangeEntry
///   Represents switching between excerpt tabs
//---------------------------------------------------------

class ExcerptChangeScriptEntry : public ScriptEntry {
      int _index;

   public:
      ExcerptChangeScriptEntry(int idx) : _index(idx) {}
      bool execute(ScriptContext& ctx) const override;
      QString serialize() const override;
      static std::unique_ptr<ScriptEntry> fromContext(const ScriptContext&);
      static std::unique_ptr<ScriptEntry> deserialize(const QStringList& tokens);
      };
}     // namespace Ms
#endif