Ardour  9.2-654-gd2ed0bd940
chord_provider.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 <vector>
22 #include <string>
23 #include <map>
24 
26 
27 namespace ARDOUR {
28 
29 class ScaleProvider;
30 
32 {
33  public:
35  virtual ~ChordProvider() {}
36 
37  typedef std::vector<int> Intervals;
38 
39  virtual bool get_midi_chord (int root_pitch, Intervals& pitches) const = 0;
40 
41  struct ChordInfo {
43  int64_t hashed;
44  std::string canonical_name;
45  std::string short_name;
46  std::vector<std::string> other_names;
47 
48  ChordInfo (Intervals const & i, int64_t hash, std::string const & canon, std::string const & shrt, std::vector<std::string> const & others)
49  : intervals (i)
50  , hashed (hash)
51  , canonical_name (canon)
52  , short_name (shrt)
53  , other_names (others) {}
54  };
55 
56  ChordInfo const * by_short_name (std::string const &) const;
57  ChordInfo const * by_canonical_name (std::string const &) const;
58  ChordInfo const * by_any_name (std::string const &) const;
59 
60  static std::vector<ChordInfo> chord_info;
61  static void load_12tet_chords ();
62  static int64_t hash_intervals (ChordProvider::Intervals const & intervals);
63  static bool add_chord (ChordInfo const &);
64 
65  static int load (std::string const & path);
66  static int save ();
67 
68  std::string identify_chord (Intervals const &);
69  std::string canonical_name (Intervals const &);
70  std::string short_name (Intervals const &);
71  std::vector<std::string> other_names (Intervals const &);
72 
74  Unison = 0,
75  MinorSecond = 1,
76  MajorSecond = 2,
77  MinorThird = 3,
78  MajorThird = 4,
79  PerfectFourth = 5,
80  Tritone = 6,
81  PerfectFifth = 7,
82  MinorSixth = 8,
83  MajorSixth = 9,
84  MinorSeventh = 10,
85  MajorSeventh = 11,
86  PerfectOctave = 12,
87 
88  /* aliases set #1 */
89 
90  P0 = PerfectOctave,
91  m2 = MinorSecond,
92  M2 = MajorSecond,
93  m3 = MinorThird,
94  M3 = MajorThird,
95  P4 = PerfectFourth,
96  A4 = Tritone,
97  d5 = Tritone,
98  P5 = PerfectFifth,
99  m6 = MinorSixth,
100  M6 = MajorSixth,
101  m7 = MinorSeventh,
102  M7 = MajorSeventh,
103  P8 = PerfectOctave,
104 
105  /* aliases set two */
106 
107  flat2 = MinorSecond,
108  fourth = PerfectFourth,
109  flat5 = Tritone,
110  sharp5 = MinorSixth,
111  dom7 = MinorSeventh,
112  dblflat7 = MajorSixth,
113 
114  /* aliases set three */
115 
116  AugmentedFifth = 8,
117  DiminishedFifth = 6,
118  DiminishedSeventh = 9,
119 
120  /* aliases set four */
121 
122  MajorNinth = 14, // Octave + 2
123  M9 = 14,
124  PerfectEleventh = 17,
125  P11 = 17,
126  MajorThirteenth = 21, // Octave + 9
127  M13 = 21,
128 
129  };
130 };
131 
132 }
static void load_12tet_chords()
ChordInfo const * by_canonical_name(std::string const &) const
std::string identify_chord(Intervals const &)
static int64_t hash_intervals(ChordProvider::Intervals const &intervals)
static std::vector< ChordInfo > chord_info
std::string canonical_name(Intervals const &)
std::vector< int > Intervals
static bool add_chord(ChordInfo const &)
virtual bool get_midi_chord(int root_pitch, Intervals &pitches) const =0
static int load(std::string const &path)
ChordInfo const * by_any_name(std::string const &) const
ChordInfo const * by_short_name(std::string const &) const
std::vector< std::string > other_names(Intervals const &)
std::string short_name(Intervals const &)
#define LIBARDOUR_API
ChordInfo(Intervals const &i, int64_t hash, std::string const &canon, std::string const &shrt, std::vector< std::string > const &others)
std::vector< std::string > other_names