1 /* -----------------------------------------------------------------------------
2 *
3 * Giada - Your Hardcore Loopmachine
4 *
5 * -----------------------------------------------------------------------------
6 *
7 * Copyright (C) 2010-2020 Giovanni A. Zuliani | Monocasual
8 *
9 * This file is part of Giada - Your Hardcore Loopmachine.
10 *
11 * Giada - Your Hardcore Loopmachine is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation, either
14 * version 3 of the License, or (at your option) any later version.
15 *
16 * Giada - Your Hardcore Loopmachine is distributed in the hope that it
17 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Giada - Your Hardcore Loopmachine. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 * -------------------------------------------------------------------------- */
26
27
28 #ifndef G_GLUE_CHANNEL_H
29 #define G_GLUE_CHANNEL_H
30
31
32 #include <optional>
33 #include <atomic>
34 #include <string>
35 #include <vector>
36 #include "core/model/model.h"
37 #include "core/types.h"
38
39
40 namespace giada {
41 namespace m
42 {
43 class Channel;
44 class SamplePlayer;
45 }
46 namespace c {
47 namespace channel
48 {
49 struct SampleData
50 {
51 SampleData() = delete;
52 SampleData(const m::SamplePlayer&, const m::AudioReceiver&);
53
54 Frame a_getTracker() const;
55 Frame a_getBegin() const;
56 Frame a_getEnd() const;
57 bool a_getInputMonitor() const;
58 bool a_getOverdubProtection() const;
59
60 ID waveId;
61 SamplePlayerMode mode;
62 bool isLoop;
63 float pitch;
64
65 private:
66
67 const m::SamplePlayer* m_samplePlayer;
68 const m::AudioReceiver* m_audioReceiver;
69 };
70
71 struct MidiData
72 {
73 MidiData() = delete;
74 MidiData(const m::MidiSender&);
75
76 bool a_isOutputEnabled() const;
77 int a_getFilter() const;
78
79 private:
80
81 const m::MidiSender* m_midiSender;
82 };
83
84 struct Data
85 {
86 Data(const m::Channel&);
87
88 bool a_getMute() const;
89 bool a_getSolo() const;
90 ChannelStatus a_getPlayStatus() const;
91 ChannelStatus a_getRecStatus() const;
92 bool a_getReadActions() const;
93 bool a_isArmed() const;
94 bool a_isRecordingInput() const;
95 bool a_isRecordingAction() const;
96
97 ID id;
98 ID columnId;
99 #ifdef WITH_VST
100 std::vector<ID> pluginIds;
101 #endif
102 ChannelType type;
103 Pixel height;
104 std::string name;
105 float volume;
106 float pan;
107 int key;
108 bool hasActions;
109
110 std::optional<SampleData> sample;
111 std::optional<MidiData> midi;
112
113 private:
114
115 const m::Channel& m_channel;
116 };
117
118 /* getChannels
119 Returns a single viewModel object filled with data from a channel. */
120
121 Data getData(ID channelId);
122
123 /* getChannels
124 Returns a vector of viewModel objects filled with data from channels. */
125
126 std::vector<Data> getChannels();
127
128 /* a_get
129 Returns an atomic property from a Channel, by locking it first. */
130
131 template <typename T>
a_get(const std::atomic<T> & a)132 T a_get(const std::atomic<T>& a)
133 {
134 m::model::ChannelsLock l(m::model::channels);
135 return a.load();
136 }
137
138 /* addChannel
139 Adds an empty new channel to the stack. */
140
141 void addChannel(ID columnId, ChannelType type);
142
143 /* loadChannel
144 Fills an existing channel with a wave. */
145
146 int loadChannel(ID columnId, const std::string& fname);
147
148 /* addAndLoadChannel
149 Adds a new Sample Channel and fills it with a wave right away. */
150
151 void addAndLoadChannel(ID columnId, const std::string& fpath);
152
153 /* addAndLoadChannels
154 As above, with multiple audio file paths in input. */
155
156 void addAndLoadChannels(ID columnId, const std::vector<std::string>& fpaths);
157
158 /* deleteChannel
159 Removes a channel from Mixer. */
160
161 void deleteChannel(ID channelId);
162
163 /* freeChannel
164 Unloads the sample from a sample channel. */
165
166 void freeChannel(ID channelId);
167
168 /* cloneChannel
169 Makes an exact copy of a channel. */
170
171 void cloneChannel(ID channelId);
172
173 /* set*
174 Sets several channel properties. */
175
176 void setInputMonitor(ID channelId, bool value);
177 void setOverdubProtection(ID channelId, bool value);
178 void setName(ID channelId, const std::string& name);
179 void setHeight(ID channelId, Pixel p);
180
181 void setSamplePlayerMode(ID channelId, SamplePlayerMode m);
182 }}} // giada::c::channel::
183
184 #endif
185