Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #ifndef MU_ENGRAVING_NOTEEVENT_H
24 : #define MU_ENGRAVING_NOTEEVENT_H
25 :
26 : #include <vector>
27 : #include <algorithm>
28 :
29 : #include "global/allocator.h"
30 :
31 : namespace mu::engraving {
32 : //---------------------------------------------------------
33 : // NoteEvent
34 : //---------------------------------------------------------
35 :
36 : class NoteEvent
37 : {
38 : public:
39 : constexpr static int NOTE_LENGTH = 1000;
40 : constexpr static double GHOST_VELOCITY_MULTIPLIER = 0.6;
41 : constexpr static double DEFAULT_VELOCITY_MULTIPLIER = 1.0;
42 : constexpr static int SLIDE_AMOUNT = 3;
43 :
44 36032 : NoteEvent() {}
45 467 : NoteEvent(int a, int b, int c, double d = 1.0, double play = true, int offset = 0)
46 467 : : m_pitch(a), m_ontime(b), m_len(c), m_velocityMultiplier(d), m_play(play), m_offset(offset) {}
47 :
48 528 : int pitch() const { return m_pitch; }
49 982 : int ontime() const { return m_ontime; }
50 0 : int offtime() const { return m_ontime + m_len; }
51 1037 : int len() const { return m_len; }
52 503 : double velocityMultiplier() const { return m_velocityMultiplier; }
53 503 : bool play() const { return m_play; }
54 950 : int offset() const { return m_offset; }
55 527 : bool slide() const { return m_slide; }
56 0 : void setPitch(int v) { m_pitch = v; }
57 0 : void setOntime(int v) { m_ontime = v; }
58 532 : void setLen(int v) { m_len = v; }
59 : void setVelocityMultiplier(double velocityMultiplier) { m_velocityMultiplier = velocityMultiplier; }
60 : void setOffset(int v) { m_offset = v; }
61 87 : void setSlide(bool slide) { m_slide = slide; }
62 :
63 : bool operator==(const NoteEvent&) const;
64 :
65 : private:
66 : int m_pitch = 0; // relative pitch to note pitch
67 : int m_ontime = 0; // one unit is 1/1000 of nominal note len
68 : int m_len = NOTE_LENGTH; // one unit is 1/1000 of nominal note len
69 : double m_velocityMultiplier = DEFAULT_VELOCITY_MULTIPLIER; // can be used to lower sound (0-1)
70 : bool m_play = true; // when 'false', note event is used only for length calculation
71 : int m_offset = 0;
72 : bool m_slide = false; // event is slide or glissando
73 : };
74 :
75 : //---------------------------------------------------------
76 : // NoteEventList
77 : //---------------------------------------------------------
78 :
79 : class NoteEventList : public std::vector<NoteEvent>
80 : {
81 : OBJECT_ALLOCATOR(engraving, NoteEventList)
82 : public:
83 : NoteEventList();
84 :
85 : int offtime()
86 : {
87 : return empty() ? 0 : std::max_element(cbegin(), cend(), [](const NoteEvent& n1, const NoteEvent& n2) {
88 : return n1.offtime() < n2.offtime();
89 : })->offtime();
90 : }
91 : };
92 : } // namespace mu::engraving
93 : #endif
|