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 : #pragma once
24 :
25 : #include <array>
26 : #include <cstdint>
27 :
28 : namespace mu::engraving {
29 : struct OrnamentInterval;
30 :
31 : struct Interval {
32 : int8_t diatonic = 0;
33 : int8_t chromatic = 0;
34 :
35 32389 : Interval() = default;
36 : Interval(int diatonic, int chromatic);
37 : Interval(int chromatic);
38 :
39 : void flip();
40 : void reduce();
41 : Interval reduced();
42 : bool isZero() const;
43 67 : bool operator!=(const Interval& a) const { return diatonic != a.diatonic || chromatic != a.chromatic; }
44 1732 : bool operator==(const Interval& a) const { return diatonic == a.diatonic && chromatic == a.chromatic; }
45 :
46 : static Interval fromOrnamentInterval(OrnamentInterval ornInt);
47 :
48 : /// An array of all supported interval sorted by size.
49 : ///
50 : /// Because intervals can be spelled differently, this array
51 : /// tracks all the different valid intervals. They are arranged
52 : /// in diatonic then chromatic order.
53 : static const std::array<Interval, 26> allIntervals;
54 :
55 : /// Finds the most likely diatonic interval for a semitone distance. Uses
56 : /// the most common diatonic intervals.
57 : /// @param semitones The number of semitones in the chromatic interval.
58 : /// Negative semitones will simply be made positive.
59 : /// @return The number of diatonic steps in the interval.
60 : static int chromatic2diatonic(int semitones);
61 : };
62 : }
|