sample_player_2d.h
1 /*************************************************************************/
2 /* sample_player_2d.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_2D_H
30 #define SAMPLE_PLAYER_2D_H
31 
32 #include "scene/2d/sound_player_2d.h"
33 #include "scene/resources/sample_library.h"
34 
35 class SamplePlayer2D : public SoundPlayer2D {
36 
37  OBJ_TYPE(SamplePlayer2D,SoundPlayer2D);
38 public:
39 
40  enum {
41 
42  INVALID_VOICE=SpatialSoundServer::SOURCE_INVALID_VOICE,
43  NEXT_VOICE=SpatialSoundServer::SOURCE_NEXT_VOICE
44  };
45 
46  typedef int VoiceID;
47 
48 
49 private:
50 
51  Ref<SampleLibrary> library;
52  int polyphony;
53  String played_back;
54  float random_pitch_scale;
55 
56 protected:
57 
58  bool _set(const StringName& p_name, const Variant& p_value);
59  bool _get(const StringName& p_name,Variant &r_ret) const;
60  void _get_property_list(List<PropertyInfo> *p_list) const;
61 
62  void _notification(int p_what);
63 
64  static void _bind_methods();
65 
66 public:
67 
68  void set_sample_library(const Ref<SampleLibrary>& p_library);
69  Ref<SampleLibrary> get_sample_library() const;
70 
71  void set_polyphony(int p_voice_count);
72  int get_polyphony() const;
73 
74  VoiceID play(const String& p_sample,int p_voice=NEXT_VOICE);
75  //voices
76  void voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale);
77  void voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db);
78 
79  bool is_voice_active(VoiceID p_voice) const;
80  void stop_voice(VoiceID p_voice);
81  void stop_all();
82 
83  void set_random_pitch_scale(float p_scale);
84  float get_random_pitch_scale() const;
85 
87  ~SamplePlayer2D();
88 
89 
90 };
91 
92 #endif // SAMPLE_PLAYER_2D_H
Definition: variant.h:74
Definition: string_db.h:48
Definition: sample_player_2d.h:35
Definition: sound_player_2d.h:38
Definition: ustring.h:64