sample_player.h
1 /*************************************************************************/
2 /* sample_player.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef SAMPLE_PLAYER_H
30 #define SAMPLE_PLAYER_H
31 
32 #include "scene/main/node.h"
33 #include "scene/resources/sample_library.h"
34 
35 class SamplePlayer : public Node {
36 
37  OBJ_TYPE( SamplePlayer, Node );
38  OBJ_CATEGORY("Audio Nodes");
39 public:
40 
41 
42  enum FilterType {
43  FILTER_NONE,
44  FILTER_LOWPASS,
45  FILTER_BANDPASS,
46  FILTER_HIPASS,
47  FILTER_NOTCH,
48  FILTER_PEAK,
50  FILTER_LOW_SHELF,
51  FILTER_HIGH_SHELF,
52  };
53 
54  enum ReverbRoomType {
55 
56  REVERB_SMALL,
57  REVERB_MEDIUM,
58  REVERB_LARGE,
59  REVERB_HALL
60  };
61 
62  enum {
63 
64  INVALID_VOICE_ID=0xFFFFFFFF
65  };
66 
67  typedef uint32_t VoiceID;
68 
69 private:
70 
71  Ref<SampleLibrary> library;
72 
73  struct Voice {
74 
75  RID voice;
76  uint32_t check;
77  bool active;
78 
79  int sample_mix_rate;
80  int mix_rate;
81  float volume;
82  float pan;
83  float pan_depth;
84  float pan_height;
85  FilterType filter_type;
86  float filter_cutoff;
87  float filter_resonance;
88  float filter_gain;
89  float chorus_send;
90  ReverbRoomType reverb_room;
91  float reverb_send;
92 
93  void clear();
94  Voice();
95  ~Voice();
96  };
97 
98  Vector<Voice> voices;
99 
100  struct Default {
101 
102  float reverb_send;
103  float pitch_scale;
104  float volume_db;
105  float pan;
106  float depth;
107  float height;
108  FilterType filter_type;
109  float filter_cutoff;
110  float filter_resonance;
111  float filter_gain;
112  float chorus_send;
113  ReverbRoomType reverb_room;
114 
115  } _default;
116 
117  uint32_t last_id;
118  uint16_t last_check;
119  String played_back;
120 protected:
121 
122  bool _set(const StringName& p_name, const Variant& p_value);
123  bool _get(const StringName& p_name,Variant &r_ret) const;
124  void _get_property_list(List<PropertyInfo> *p_list) const;
125 
126  static void _bind_methods();
127 
128 public:
129 
130  void set_sample_library(const Ref<SampleLibrary>& p_library);
131  Ref<SampleLibrary> get_sample_library() const;
132 
133  void set_polyphony(int p_voice_count);
134  int get_polyphony() const;
135 
136  VoiceID play(const String& p_name,bool unique=false);
137  void stop(VoiceID p_voice);
138  void stop_all();
139  bool is_voice_active(VoiceID) const;
140  bool is_active() const;
141 
142  void set_mix_rate(VoiceID p_voice, int p_mix_rate);
143  void set_pitch_scale(VoiceID p_voice, float p_pitch_scale);
144  void set_volume(VoiceID p_voice, float p_volume);
145  void set_volume_db(VoiceID p_voice, float p_db);
146  void set_pan(VoiceID p_voice, float p_pan,float p_pan_depth=0,float p_pan_height=0);
147  void set_filter(VoiceID p_voice,FilterType p_filter,float p_cutoff,float p_resonance,float p_gain);
148  void set_chorus(VoiceID p_voice,float p_send);
149  void set_reverb(VoiceID p_voice,ReverbRoomType p_room,float p_send);
150 
151  int get_mix_rate(VoiceID p_voice) const;
152  float get_pitch_scale(VoiceID p_voice) const;
153  float get_volume(VoiceID p_voice) const;
154  float get_volume_db(VoiceID p_voice) const;
155 
156  float get_pan(VoiceID p_voice) const;
157  float get_pan_depth(VoiceID p_voice) const;
158  float get_pan_height(VoiceID p_voice) const;
159  FilterType get_filter_type(VoiceID p_voice) const;
160  float get_filter_cutoff(VoiceID p_voice) const;
161  float get_filter_resonance(VoiceID p_voice) const;
162  float get_filter_gain(VoiceID p_voice) const;
163  float get_chorus(VoiceID p_voice) const;
164  ReverbRoomType get_reverb_room(VoiceID p_voice) const;
165  float get_reverb(VoiceID p_voice) const;
166 
167 
168 
169  void set_default_pitch_scale(float p_pitch_scale);
170  void set_default_volume(float p_volume);
171  void set_default_volume_db(float p_db);
172  void set_default_pan(float p_pan,float p_pan_depth=0,float p_pan_height=0);
173  void set_default_filter(FilterType p_filter,float p_cutoff,float p_resonance,float p_gain);
174  void set_default_chorus(float p_send);
175  void set_default_reverb(ReverbRoomType p_room,float p_send);
176 
177  float get_default_volume() const;
178  float get_default_volume_db() const;
179  float get_default_pitch_scale() const;
180  float get_default_pan() const;
181  float get_default_pan_depth() const;
182  float get_default_pan_height() const;
183  FilterType get_default_filter_type() const;
184  float get_default_filter_cutoff() const;
185  float get_default_filter_resonance() const;
186  float get_default_filter_gain() const;
187  float get_default_chorus() const;
188  ReverbRoomType get_default_reverb_room() const;
189  float get_default_reverb() const;
190 
191  SamplePlayer();
192  ~SamplePlayer();
193 };
194 
195 VARIANT_ENUM_CAST( SamplePlayer::FilterType );
196 VARIANT_ENUM_CAST( SamplePlayer::ReverbRoomType );
197 
198 #endif // SAMPLE_PLAYER_H
FilterType
Definition: sample_player.h:42
Definition: variant.h:74
Definition: node.h:42
cutoff is LP resonace is HP
Definition: sample_player.h:49
Definition: sample_player.h:35
Definition: string_db.h:48
Definition: rid.h:47
static void _bind_methods()
Definition: sample_player.cpp:604
Definition: ustring.h:64