Ardour  9.2-541-gc1841a13dd
ardour/ardour/scale.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2026 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <string>
22 #include <vector>
23 
24 #include "pbd/signals.h"
25 
26 namespace ARDOUR {
27 
35 };
36 
44  China
45 };
46 
47 class MusicalMode {
48  public:
49 
50  enum Name {
87  Algerian
88  };
89 
90  MusicalMode (std::string const & name, MusicalModeType type, std::vector<float> const & elements);
91  MusicalMode (MusicalMode const & other);
93  MusicalMode (std::ifstream& file); /* Read from a Scala file */
94 
96 
97  std::string name() const { return _name; }
98  MusicalModeType type() const { return _type; }
99  int size() const { return _elements.size(); }
100  std::vector<float> const & elements() const { return _elements; }
101 
102  std::vector<float> pitches_from_root (float root, int steps) const;
103  std::vector<int> as_midi (int scale_root) const;
104  void set_name (std::string const & str);
105 
108 
109  protected:
110  std::string _name;
112  std::vector<float> _elements;
113 
114  void fill (Name);
115 
116  std::vector<float> absolute_pitch_pitches_from_root (float root, int steps) const;
117  std::vector<float> semitone_steps_pitches_from_root (float root, int steps) const;
118  std::vector<float> wholetone_steps_pitches_from_root (float root, int steps) const;
119  std::vector<float> ratio_steps_pitches_from_root (float root, int steps) const;
120  std::vector<float> ratio_from_root_pitches_from_root (float root, int steps) const;
121  std::vector<float> midi_note_pitches_from_root (float root, int steps) const;
122 
123  std::vector<int> absolute_pitch_as_midi (int root) const;
124  std::vector<int> semitone_steps_as_midi (int root) const;
125  std::vector<int> wholetone_steps_as_midi (int root) const;
126  std::vector<int> ratio_steps_as_midi (int root) const;
127  std::vector<int> ratio_from_root_as_midi (int root) const;
128  std::vector<int> midi_note_as_midi (int root) const;
129 };
130 
131 
132 class MusicalKey : public MusicalMode
133 {
134  public:
135  MusicalKey (float root, MusicalMode const &);
136  MusicalKey (MusicalKey const & other);
137 
139 
140  float root() const { return _root; }
141  float nth (int n) const;
142 
143  private:
144  float _root;
145 
146 };
147 
148 } // namespace
float nth(int n) const
MusicalKey(MusicalKey const &other)
MusicalKey(float root, MusicalMode const &)
MusicalKey operator=(MusicalKey const &other)
MusicalMode(std::ifstream &file)
std::vector< int > ratio_steps_as_midi(int root) const
std::vector< float > pitches_from_root(float root, int steps) const
std::vector< int > semitone_steps_as_midi(int root) const
std::vector< float > wholetone_steps_pitches_from_root(float root, int steps) const
PBD::Signal< void()> NameChanged
void set_name(std::string const &str)
std::vector< float > ratio_from_root_pitches_from_root(float root, int steps) const
MusicalModeType type() const
std::vector< float > midi_note_pitches_from_root(float root, int steps) const
std::vector< float > const & elements() const
std::vector< int > absolute_pitch_as_midi(int root) const
std::vector< float > _elements
PBD::Signal< void()> Changed
MusicalMode operator=(MusicalMode const &other)
std::string name() const
std::vector< int > as_midi(int scale_root) const
std::vector< int > wholetone_steps_as_midi(int root) const
std::vector< int > midi_note_as_midi(int root) const
MusicalMode(std::string const &name, MusicalModeType type, std::vector< float > const &elements)
MusicalMode(MusicalMode const &other)
MusicalMode(MusicalMode::Name)
std::vector< float > absolute_pitch_pitches_from_root(float root, int steps) const
std::vector< float > ratio_steps_pitches_from_root(float root, int steps) const
std::vector< int > ratio_from_root_as_midi(int root) const
std::vector< float > semitone_steps_pitches_from_root(float root, int steps) const