MuseScore  3.4
Music composition and notation
noteevent.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2010-2012 Werner Schweer
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 __NOTEEVENT_H__
14 #define __NOTEEVENT_H__
15 
16 namespace Ms {
17 
18 class XmlWriter;
19 class XmlReader;
20 
21 //---------------------------------------------------------
22 // NoteEvent
23 //---------------------------------------------------------
24 
25 class NoteEvent {
26  int _pitch; // relative pitch to note pitch
27  int _ontime; // 1/1000 of nominal note len
28  int _len; // 1/1000 of nominal note len
29 
30  public:
31  constexpr static int NOTE_LENGTH = 1000;
32 
33  NoteEvent() : _pitch(0), _ontime(0), _len(NOTE_LENGTH) {}
34  NoteEvent(int a, int b, int c) : _pitch(a), _ontime(b), _len(c) {}
35 
36  void read(XmlReader&);
37  void write(XmlWriter&) const;
38 
39  int pitch() const { return _pitch; }
40  int ontime() const { return _ontime; }
41  int offtime() const { return _ontime + _len; }
42  int len() const { return _len; }
43  void setPitch(int v) { _pitch = v; }
44  void setOntime(int v) { _ontime = v; }
45  void setLen(int v) { _len = v; }
46  bool operator==(const NoteEvent&) const;
47  };
48 
49 //---------------------------------------------------------
50 // NoteEventList
51 //---------------------------------------------------------
52 
53 class NoteEventList : public QList<NoteEvent> {
54  public:
55  NoteEventList();
56 
57  int offtime() { return empty() ? 0 : std::max_element(cbegin(), cend(), [](const NoteEvent& n1, const NoteEvent& n2) { return n1.offtime() < n2.offtime(); })->offtime(); }
58  };
59 
60 
61 } // namespace Ms
62 #endif
NoteEvent(int a, int b, int c)
Definition: noteevent.h:34
void write(XmlWriter &) const
Definition: noteevent.cpp:41
bool operator==(const NoteEvent &) const
Definition: noteevent.cpp:63
Definition: noteevent.h:25
int _ontime
Definition: noteevent.h:27
Definition: xml.h:67
int ontime() const
Definition: noteevent.h:40
void setPitch(int v)
Definition: noteevent.h:43
Definition: noteevent.h:53
void read(XmlReader &)
Definition: noteevent.cpp:22
void setOntime(int v)
Definition: noteevent.h:44
NoteEvent()
Definition: noteevent.h:33
Definition: aeolus.cpp:26
Definition: xml.h:218
int _pitch
Definition: noteevent.h:26
static constexpr int NOTE_LENGTH
Definition: noteevent.h:31
Definition: xmlwriter.h:26
Definition: xmlreader.h:28
int _len
Definition: noteevent.h:28
int pitch() const
Definition: noteevent.h:39
int offtime()
Definition: noteevent.h:57
int len() const
Definition: noteevent.h:42
int offtime() const
Definition: noteevent.h:41
void setLen(int v)
Definition: noteevent.h:45