MuseScore Plugins 3.3
Plugins API for MuseScore
Loading...
Searching...
No Matches
playevent.h
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
19namespace Ms {
20namespace PluginAPI {
21
22class 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
32class 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:
54 Ms::NoteEvent* ne;
55 Note* parentNote;
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
84inline PlayEvent* playEventWrap(Ms::NoteEvent* t, Note* parent)
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
103class 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
115inline QmlPlayEventsListAccess wrapPlayEventsContainerProperty(QObject* obj, NoteEventList& c)
116 {
117 return QmlPlayEventsListAccess(obj, c);
118 }
119
120} // namespace PluginAPI
121} // namespace Ms
122#endif
Definition elements.h:429
Definition playevent.h:32
int pitch
The relative pitch to the note pitch.
Definition playevent.h:37
int offtime
Time note will turn off.
Definition playevent.h:50
int ontime
Time to turn on the note event.
Definition playevent.h:41
int len
The length of time for the event.
Definition playevent.h:45
Definition playevent.h:103
Definition cursor.cpp:30