Debian Codegraph @

BambooTracker/module/song.hpp

raw
1 /*
2 * Copyright (C) 2018-2021 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #pragma once
27
28 #include <vector>
29 #include <set>
30 #include <string>
31 #include <unordered_map>
32 #include "track.hpp"
33
34 enum class SongType
35 {
36 Standard,
37 FM3chExpanded
38 };
39
40 struct SongStyle
41 {
42 SongType type;
43 std::vector<TrackAttribute> trackAttribs; // Always sorted by number
44 };
45
46 struct Bookmark
47 {
48 std::string name = u8"";
49 int order, step;
50
51 Bookmark(const std::string& argname, int argorder, int argstep);
52 };
53
54 struct KeySignature
55 {
56 enum Type : int
57 {
58 C = 0,
59 CS = 1,
60 DF = 2,
61 D = 3,
62 DS = 4,
63 EF = 5,
64 E = 6,
65 FF = 7,
66 ES = 8,
67 F = 9,
68 FS = 10,
69 GF = 11,
70 G = 12,
71 GS = 13,
72 AF = 14,
73 A = 15,
74 AS = 16,
75 BF = 17,
76 B = 18,
77 CF = 19,
78 BS = 20,
79 FISRT = C,
80 LAST = BS
81 } type;
82 int order, step;
83
84 KeySignature(Type type, int scorder, int scstep);
85 };
86
87 class Song
88 {
89 public:
90 Song(int number, SongType songType = SongType::Standard, const std::string& title = u8"",
91 bool isUsedTempo = true, int tempo = 150, int groove = 0, int speed = 6,
92 size_t defaultPatternSize = 64);
93
94 void setNumber(int n) noexcept { num_ = n; }
95 int getNumber() const noexcept { return num_; }
96 void setTitle(const std::string& title) { title_ = title; }
97 std::string getTitle() const noexcept { return title_; }
98 void setTempo(int tempo) noexcept { tempo_ = tempo; }
99 int getTempo() const noexcept { return tempo_; }
100 void setGroove(int groove) noexcept { groove_ = groove; }
101 int getGroove() const noexcept { return groove_; }
102 void toggleTempoOrGroove(bool isUsedTempo) noexcept { isUsedTempo_ = isUsedTempo; }
103 bool isUsedTempo() const noexcept { return isUsedTempo_; }
104 void setSpeed(int speed) noexcept { speed_ = speed; }
105 int getSpeed() const noexcept { return speed_; }
106 void setDefaultPatternSize(size_t size);
107 size_t getDefaultPatternSize() const noexcept { return defPtnSize_; }
108 size_t getPatternSizeFromOrderNumber(int order);
109
110 SongStyle getStyle() const;
111 std::vector<TrackAttribute> getTrackAttributes() const;
112 Track& getTrack(int num);
113 void changeType(SongType type);
114
115 std::vector<OrderInfo> getOrderData(int order) const;
116 size_t getOrderSize() const;
117 bool canAddNewOrder() const;
118 void insertOrderBelow(int order);
119 void deleteOrder(int order);
120 void swapOrder(int a, int b);
121
122 std::set<int> getRegisteredInstruments() const;
123
124 void clearUnusedPatterns();
125 void replaceDuplicateInstrumentsInPatterns(const std::unordered_map<int, int>& map);
126
127 void transpose(int semitones, const std::vector<int>& excludeInsts);
128 void swapTracks(int track1, int track2);
129
130 // Bookmark
131 int addBookmark(const std::string& name, int order, int step);
132 void changeBookmark(int i, const std::string& name, int order, int step);
133 void removeBookmark(int i);
134 void clearBookmark();
135 void swapBookmarks(int a, int b);
136 void sortBookmarkByPosition();
137 void sortBookmarkByName();
138 Bookmark getBookmark(int i) const;
139 std::vector<int> findBookmarks(int order, int step) const;
140 Bookmark getPreviousBookmark(int order, int step) const;
141 Bookmark getNextBookmark(int order, int step) const;
142 size_t getBookmarkSize() const;
143
144 // Key signature
145 void addKeySignature(KeySignature::Type key, int order, int step);
146 void changeKeySignature(int i, KeySignature::Type key, int order, int step);
147 void removeKeySignature(int i);
148 void clearKeySignature();
149 KeySignature getKeySignature(int i) const;
150 size_t getKeySignatureSize() const;
151 KeySignature::Type searchKeySignatureAt(int order, int step) const;
152
153 static size_t getFMChannelCount(SongType type)
154 {
155 switch (type) {
156 case SongType::Standard: return 6;
157 case SongType::FM3chExpanded: return 9;
158 default: throw std::invalid_argument("Invalid SongType.");
159 }
160 }
161
162 private:
163 int num_;
164 SongType type_;
165 std::string title_;
166 bool isUsedTempo_;
167 int tempo_;
168 int groove_;
169 int speed_;
170 size_t defPtnSize_;
171
172 std::vector<Track> tracks_;
173 std::vector<Bookmark> bms_;
174 std::vector<KeySignature> sigs_;
175
176 std::vector<Bookmark> getSortedBookmarkList() const;
177 };