supertux
sound_object.hpp
1 // SuperTux
2 // Copyright (C) 2023 mrkubax10 <mrkubax10@onet.pl>
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 3 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
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_SOUND_OBJECT_HPP
18 #define HEADER_SUPERTUX_SOUND_OBJECT_HPP
19 
20 #include "supertux/game_object.hpp"
21 
22 class SoundSource;
23 
25 class SoundObject final : public GameObject
26 {
27 public:
28  static void register_class(ssq::VM& vm);
29 
30 public:
31  SoundObject(const ReaderMapping& mapping);
32  SoundObject(float vol, const std::string& file);
33  ~SoundObject() override;
34 
35  virtual void draw(DrawingContext& context) override {}
36  virtual void update(float dt_sec) override;
37 
38  static std::string class_name() { return "sound-object"; }
39  virtual std::string get_class_name() const override { return class_name(); }
40  virtual std::string get_exposed_class_name() const override { return "SoundObject"; }
41  static std::string display_name() { return _("Sound"); }
42  virtual std::string get_display_name() const override { return display_name(); }
43  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(SoundObject)); }
44  virtual const std::string get_icon_path() const override { return "images/engine/editor/sound.png"; }
45 
46  virtual ObjectSettings get_settings() override;
47 
48  virtual void stop_looping_sounds() override;
49  virtual void play_looping_sounds() override;
50 
54 #ifdef DOXYGEN_SCRIPTING
55 
58  void start_playing();
62  void stop_playing();
63 #endif
64 
69  void set_volume(float volume);
73  float get_volume() const;
74 
77 private:
78  std::string m_sample;
79  std::unique_ptr<SoundSource> m_sound_source;
80  float m_volume;
81  bool m_started;
82 
83 private:
84  void prepare_sound_source();
85 
86 private:
87  SoundObject(const SoundObject&) = delete;
88  SoundObject& operator=(const SoundObject&) = delete;
89 };
90 
91 #endif
92 
93 /* EOF */
virtual void stop_looping_sounds() override
stops all looping sounds
Definition: sound_object.cpp:81
void set_volume(float volume)
Sets the volume of sound played by SoundObject.
Definition: sound_object.cpp:126
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: sound_object.hpp:42
float get_volume() const
Returns the volume of sound played by SoundObject.
Definition: sound_object.cpp:133
Definition: object_settings.hpp:39
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: sound_object.hpp:43
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: sound_object.hpp:35
Plays sound at given interval with specified volume hearable in entire Sector.
Definition: sound_object.hpp:25
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: sound_object.cpp:57
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
A sound source represents the source of audio output.
Definition: sound_source.hpp:25
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
virtual void play_looping_sounds() override
continues all looping sounds
Definition: sound_object.cpp:88