LMMS
Loading...
Searching...
No Matches
Scale.h
Go to the documentation of this file.
1/*
2 * Scale.h - holds information about a scale and its intervals
3 *
4 * Copyright (c) 2020 Martin Pavelek <he29.HS/at/gmail.com>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_SCALE_H
26#define LMMS_SCALE_H
27
28#include <cstdint>
29#include <vector>
30#include <QObject>
31#include <QString>
32
33#include "SerializingObject.h"
34
35namespace lmms
36{
37
39{
40public:
42 explicit Interval(float cents);
43 Interval(uint32_t numerator, uint32_t denominator);
44
45 float getRatio() const {return m_ratio;}
46
47 QString getString() const
48 {
49 if (m_denominator) {return QString::number(m_numerator) + "/" + QString::number(m_denominator);}
50 else {return QString("%1").arg(m_cents, 0, 'f', 4);}
51 }
52
53 void saveSettings(QDomDocument &doc, QDomElement &element) override;
54 void loadSettings(const QDomElement &element) override;
55 inline QString nodeName() const override {return "interval";}
56
57private:
58 // Scala specifies that numerators and denominators should go at least up to 2147483647 → use uint32_t.
61 float m_cents;
62 float m_ratio;
63};
64
65
66class Scale : public QObject, public SerializingObject
67{
68 Q_OBJECT
69public:
70 Scale();
71 Scale(QString description, std::vector<Interval> intervals);
72
73 QString getDescription() const;
74 void setDescription(QString description);
75
76 const std::vector<Interval> &getIntervals() const {return m_intervals;}
77 void setIntervals(std::vector<Interval> input) {m_intervals = std::move(input);}
78
79 void saveSettings(QDomDocument &doc, QDomElement &element) override;
80 void loadSettings(const QDomElement &element) override;
81 inline QString nodeName() const override {return "scale";}
82
83private:
84 QString m_description;
85 std::vector<Interval> m_intervals;
86
87};
88
89
90} // namespace lmms
91
92#endif // LMMS_SCALE_H
uint32_t m_denominator
denominator of the interval fraction
Definition Scale.h:60
QString getString() const
Definition Scale.h:47
void loadSettings(const QDomElement &element) override
Definition Scale.cpp:65
float getRatio() const
Definition Scale.h:45
void saveSettings(QDomDocument &doc, QDomElement &element) override
Definition Scale.cpp:51
Interval()
Definition Scale.h:41
float m_ratio
precomputed output value for better performance
Definition Scale.h:62
float m_cents
interval defined in cents (used when denominator is set to zero)
Definition Scale.h:61
QString nodeName() const override
Definition Scale.h:55
uint32_t m_numerator
numerator of the interval fraction
Definition Scale.h:59
QString m_description
name or description of the scale
Definition Scale.h:84
const std::vector< Interval > & getIntervals() const
Definition Scale.h:76
QString nodeName() const override
Definition Scale.h:81
QString getDescription() const
Definition Scale.cpp:88
void saveSettings(QDomDocument &doc, QDomElement &element) override
Definition Scale.cpp:100
std::vector< Interval > m_intervals
a series of ratios that define the scale
Definition Scale.h:85
void setDescription(QString description)
Definition Scale.cpp:94
void setIntervals(std::vector< Interval > input)
Definition Scale.h:77
Scale()
Definition Scale.cpp:75
void loadSettings(const QDomElement &element) override
Definition Scale.cpp:112
SerializingObject()
Definition SerializingObject.cpp:32
unsigned int uint32_t
Definition mid.cpp:100
Definition AudioAlsa.cpp:35