MuseScore  3.4
Music composition and notation
playevent.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2019 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __PLUGIN_API_PLAYEVENT_H__
14 #define __PLUGIN_API_PLAYEVENT_H__
15 
16 #include "libmscore/noteevent.h"
17 #include "elements.h"
18 
19 namespace Ms {
20 namespace PluginAPI {
21 
22 class Note;
23 
24 //---------------------------------------------------------
25 // PlayEvent
26 // Wrapper class for internal Ms::NoteEvent
27 //
28 // This is based on the wrapper in excerpt.h.
30 //---------------------------------------------------------
31 
32 class PlayEvent : public QObject {
33  Q_OBJECT
37  Q_PROPERTY(int pitch READ pitch WRITE setPitch)
41  Q_PROPERTY(int ontime READ ontime WRITE setOntime)
45  Q_PROPERTY(int len READ len WRITE setLen)
50  Q_PROPERTY(int offtime READ offtime)
52 
53  protected:
56 
57  public:
58 
59  PlayEvent(Ms::NoteEvent* _ne = new Ms::NoteEvent(), Note* _parent = nullptr)
60  : QObject(), ne(_ne), parentNote(_parent) {}
61  // Delete the NoteEvent if parentless.
62  virtual ~PlayEvent() { if (parentNote == nullptr) delete ne; }
63 
64  const Ms::NoteEvent& getNoteEvent() { return *ne; }
65  void setParentNote(Note* parent) { this->parentNote = parent; }
66  Note* note() { return parentNote; }
67 
68  int pitch() const { return ne->pitch(); }
69  int ontime() const { return ne->ontime(); }
70  int offtime() const { return ne->offtime(); }
71  int len() const { return ne->len(); }
72  void setPitch(int v);
73  void setOntime(int v);
74  void setLen(int v);
76 };
77 
78 //---------------------------------------------------------
79 // wrap
82 //---------------------------------------------------------
83 
85  {
86  PlayEvent* w = t ? new PlayEvent(t, parent) : nullptr;
87  // All wrapper objects should belong to JavaScript code.
88  QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
89  return w;
90  }
91 
92 //---------------------------------------------------------
93 // QML access to containers of NoteEvent
94 //
95 // QmlNoteEventsListAccess provides a convenience interface
96 // for QQmlListProperty providing access to plugins for NoteEvent
97 // Containers.
98 //
99 // Based on QmlListAccess in excerpt.h
100 //---------------------------------------------------------
101 
102 
103 class QmlPlayEventsListAccess : public QQmlListProperty<PlayEvent> {
104  public:
105  QmlPlayEventsListAccess(QObject* obj, NoteEventList& container)
106  : QQmlListProperty<PlayEvent>(obj, &container, &append, &count, &at, &clear) {};
107 
108  static int count(QQmlListProperty<PlayEvent>* l) { return int(static_cast<NoteEventList*>(l->data)->size()); }
109  static PlayEvent* at(QQmlListProperty<PlayEvent>* l, int i) { return playEventWrap(&(*(static_cast<NoteEventList*>(l->data)))[i], reinterpret_cast<Note*>(l->object)); }
110  static void clear(QQmlListProperty<PlayEvent>* l);
111  static void append(QQmlListProperty<PlayEvent>* l, PlayEvent *v);
112 };
113 
116  {
117  return QmlPlayEventsListAccess(obj, c);
118  }
119 
120 } // namespace PluginAPI
121 } // namespace Ms
122 #endif
int ontime() const
Definition: playevent.h:69
Definition: noteevent.h:25
static int count(QQmlListProperty< PlayEvent > *l)
Definition: playevent.h:108
int ontime() const
Definition: noteevent.h:40
Note * parentNote
Definition: playevent.h:55
void setParentNote(Note *parent)
Definition: playevent.h:65
Definition: playevent.h:103
QmlPlayEventsListAccess(QObject *obj, NoteEventList &container)
Definition: playevent.h:105
PlayEvent * playEventWrap(Ms::NoteEvent *t, Note *parent)
Definition: playevent.h:84
int pitch() const
Definition: playevent.h:68
Definition: noteevent.h:53
void setPitch(int v)
Definition: playevent.cpp:26
Definition: playevent.h:32
Note * note()
Definition: playevent.h:66
virtual ~PlayEvent()
Definition: playevent.h:62
Definition: aeolus.cpp:26
PlayEvent(Ms::NoteEvent *_ne=new Ms::NoteEvent(), Note *_parent=nullptr)
Definition: playevent.h:59
int len() const
Definition: playevent.h:71
void setOntime(int v)
Definition: playevent.cpp:70
Ms::NoteEvent * ne
Definition: playevent.h:54
QmlPlayEventsListAccess wrapPlayEventsContainerProperty(QObject *obj, NoteEventList &c)
Definition: playevent.h:115
Graphic representation of a note.
Definition: note.h:212
void setLen(int v)
Definition: playevent.cpp:102
int pitch() const
Definition: noteevent.h:39
static PlayEvent * at(QQmlListProperty< PlayEvent > *l, int i)
Definition: playevent.h:109
const Ms::NoteEvent & getNoteEvent()
Definition: playevent.h:64
Definition: event.h:219
int len() const
Definition: noteevent.h:42
int offtime() const
Definition: noteevent.h:41
Definition: elements.h:395
int offtime() const
Definition: playevent.h:70