← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/notifications_sound into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/notifications_sound into lp:widelands.

Commit message:
Use notifications to remove dependencies from sound to logic and wui. Animation::trigger_sound is now called in Animation::blit. Moved widelands.h to wl_library logic_constants.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/notifications_sound/+merge/318763
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/notifications_sound into lp:widelands.
=== modified file 'src/ai/CMakeLists.txt'
--- src/ai/CMakeLists.txt	2016-11-24 19:45:32 +0000
+++ src/ai/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -18,5 +18,6 @@
     base_time_string
     economy
     logic
+    logic_constants
     scripting_lua_table
 )

=== modified file 'src/economy/CMakeLists.txt'
--- src/economy/CMakeLists.txt	2017-02-22 20:23:49 +0000
+++ src/economy/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -52,6 +52,7 @@
     base_macros
     io_fileread
     logic
+    logic_constants
     logic_widelands_geometry
     map_io
     notifications

=== modified file 'src/editor/CMakeLists.txt'
--- src/editor/CMakeLists.txt	2016-11-18 07:11:51 +0000
+++ src/editor/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -97,6 +97,7 @@
     graphic_surface
     io_filesystem
     logic
+    logic_constants
     logic_widelands_geometry
     map_io
     map_io_map_loader

=== modified file 'src/graphic/CMakeLists.txt'
--- src/graphic/CMakeLists.txt	2016-10-25 07:07:14 +0000
+++ src/graphic/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -133,6 +133,7 @@
     graphic_surface
     io_filesystem
     logic
+    logic_constants
     logic_widelands_geometry
 )
 
@@ -273,7 +274,8 @@
     io_fileread
     io_filesystem
     io_stream
-    logic
+    logic_constants
+    note_sound
     notifications
     scripting_lua_table
     sound

=== modified file 'src/graphic/animation.cc'
--- src/graphic/animation.cc	2017-01-25 18:55:59 +0000
+++ src/graphic/animation.cc	2017-03-02 12:42:56 +0000
@@ -38,6 +38,7 @@
 #include "graphic/texture.h"
 #include "io/filesystem/layered_filesystem.h"
 #include "scripting/lua_table.h"
+#include "sound/note_sound.h"
 #include "sound/sound_handler.h"
 
 using namespace std;
@@ -253,7 +254,7 @@
 	const uint32_t framenumber = current_frame(time);
 
 	if (framenumber == 0) {
-		g_sound_handler.play_fx(sound_effect_, stereo_position, 1);
+		Notifications::publish(NoteSound(sound_effect_, stereo_position, 1));
 	}
 }
 
@@ -287,6 +288,8 @@
 		target->blit_blended(
 		   destination_rect, *frames_.at(idx), *pcmasks_.at(idx), source_rect, *clr);
 	}
+	// TODO(GunChleoc): Stereo position would be nice.
+	trigger_sound(time, 128);
 }
 
 }  // namespace

=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc	2017-02-23 19:38:51 +0000
+++ src/graphic/rendertarget.cc	2017-03-02 12:42:56 +0000
@@ -330,12 +330,6 @@
 			animation.blit(time, srcrc, dstrc, player_color, surface_);
 		}
 	}
-
-	// Look if there is a sound effect registered for this frame and trigger the
-	// effect (see SoundHandler::stereo_position).
-	// TODO(sirver): Playing a sound effect in here is rather silly. What if
-	// this animation is used in the menus?
-	animation.trigger_sound(time, 128);
 }
 
 /**

=== modified file 'src/logic/CMakeLists.txt'
--- src/logic/CMakeLists.txt	2016-10-27 05:37:54 +0000
+++ src/logic/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -14,6 +14,7 @@
     base_exceptions
     io_filesystem
     logic
+    logic_constants
     scripting_lua_interface
     scripting_lua_table
 )
@@ -28,6 +29,7 @@
   DEPENDS
     ai
     logic
+    logic_constants
     profile
     ui_basic
     widelands_ball_of_mud
@@ -48,6 +50,9 @@
   SRCS
     constants.h
     constants.cc
+    widelands.h
+  DEPENDS
+    base_macros
 )
 
 wl_library(logic
@@ -123,7 +128,6 @@
     save_handler.h
     widelands_geometry_io.cc
     widelands_geometry_io.h
-    widelands.h
     map_objects/draw_text.h
     map_objects/attackable.h
     map_objects/bob.cc
@@ -240,6 +244,7 @@
     map_io
     map_io_map_loader
     network
+    note_sound
     notifications
     random
     scripting_coroutine

=== modified file 'src/logic/editor_game_base.cc'
--- src/logic/editor_game_base.cc	2017-01-25 18:55:59 +0000
+++ src/logic/editor_game_base.cc	2017-03-02 12:42:56 +0000
@@ -50,7 +50,6 @@
 #include "logic/roadtype.h"
 #include "scripting/logic.h"
 #include "scripting/lua_table.h"
-#include "sound/sound_handler.h"
 #include "ui_basic/progresswindow.h"
 #include "wui/interactive_base.h"
 #include "wui/interactive_gamebase.h"
@@ -73,14 +72,11 @@
      lasttrackserial_(0) {
 	if (!lua_)  // TODO(SirVer): this is sooo ugly, I can't say
 		lua_.reset(new LuaEditorInterface(this));
-
-	g_sound_handler.egbase_ = this;
 }
 
 EditorGameBase::~EditorGameBase() {
 	delete map_;
 	delete player_manager_.release();
-	g_sound_handler.egbase_ = nullptr;
 }
 
 void EditorGameBase::think() {

=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2017-01-25 18:55:59 +0000
+++ src/logic/game.cc	2017-03-02 12:42:56 +0000
@@ -62,7 +62,6 @@
 #include "network/network.h"
 #include "scripting/logic.h"
 #include "scripting/lua_table.h"
-#include "sound/sound_handler.h"
 #include "ui_basic/progresswindow.h"
 #include "wlapplication.h"
 #include "wui/game_tips.h"

=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc	2017-02-14 19:59:29 +0000
+++ src/logic/map_objects/immovable.cc	2017-03-02 12:42:56 +0000
@@ -53,6 +53,7 @@
 #include "map_io/world_legacy_lookup_table.h"
 #include "notifications/notifications.h"
 #include "scripting/lua_table.h"
+#include "sound/note_sound.h"
 #include "sound/sound_handler.h"
 
 namespace Widelands {
@@ -805,7 +806,7 @@
  * Whether the effect actually gets played
  * is decided only by the sound server*/
 void ImmovableProgram::ActPlaySound::execute(Game& game, Immovable& immovable) const {
-	g_sound_handler.play_fx(name, immovable.get_position(), priority);
+	Notifications::publish(NoteSound(name, immovable.get_position(), priority));
 	immovable.program_step(game);
 }
 

=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc	2017-02-14 21:49:40 +0000
+++ src/logic/map_objects/tribes/building.cc	2017-03-02 12:42:56 +0000
@@ -46,7 +46,6 @@
 #include "logic/map_objects/tribes/tribes.h"
 #include "logic/map_objects/tribes/worker.h"
 #include "logic/player.h"
-#include "sound/sound_handler.h"
 
 namespace Widelands {
 

=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
--- src/logic/map_objects/tribes/constructionsite.cc	2017-02-14 21:49:40 +0000
+++ src/logic/map_objects/tribes/constructionsite.cc	2017-03-02 12:42:56 +0000
@@ -35,7 +35,6 @@
 #include "logic/game.h"
 #include "logic/map_objects/tribes/tribe_descr.h"
 #include "logic/map_objects/tribes/worker.h"
-#include "sound/sound_handler.h"
 #include "ui_basic/window.h"
 
 namespace Widelands {

=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
--- src/logic/map_objects/tribes/dismantlesite.cc	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/dismantlesite.cc	2017-03-02 12:42:56 +0000
@@ -35,7 +35,6 @@
 #include "logic/game.h"
 #include "logic/map_objects/tribes/tribe_descr.h"
 #include "logic/map_objects/tribes/worker.h"
-#include "sound/sound_handler.h"
 
 namespace Widelands {
 

=== modified file 'src/logic/map_objects/tribes/partially_finished_building.cc'
--- src/logic/map_objects/tribes/partially_finished_building.cc	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/partially_finished_building.cc	2017-03-02 12:42:56 +0000
@@ -26,7 +26,7 @@
 #include "logic/map_objects/tribes/tribe_descr.h"
 #include "logic/map_objects/tribes/worker.h"
 #include "logic/player.h"
-#include "sound/sound_handler.h"
+#include "sound/note_sound.h"
 
 namespace Widelands {
 
@@ -72,7 +72,7 @@
 	if (upcast(Game, game, &egbase))
 		request_builder(*game);
 
-	g_sound_handler.play_fx("create_construction_site", position_, 255);
+	Notifications::publish(NoteSound("create_construction_site", position_, 255));
 }
 
 /*

=== modified file 'src/logic/map_objects/tribes/production_program.cc'
--- src/logic/map_objects/tribes/production_program.cc	2017-02-12 09:10:57 +0000
+++ src/logic/map_objects/tribes/production_program.cc	2017-03-02 12:42:56 +0000
@@ -51,6 +51,7 @@
 #include "logic/mapregion.h"
 #include "logic/message_queue.h"
 #include "logic/player.h"
+#include "sound/note_sound.h"
 #include "sound/sound_handler.h"
 
 namespace Widelands {
@@ -1430,7 +1431,7 @@
 }
 
 void ProductionProgram::ActPlaySound::execute(Game& game, ProductionSite& ps) const {
-	g_sound_handler.play_fx(name, ps.position_, priority);
+	Notifications::publish(NoteSound(name, ps.position_, priority));
 	return ps.program_step(game);
 }
 

=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc	2017-02-11 12:38:17 +0000
+++ src/logic/map_objects/tribes/worker.cc	2017-03-02 12:42:56 +0000
@@ -61,7 +61,7 @@
 #include "map_io/map_object_loader.h"
 #include "map_io/map_object_saver.h"
 #include "map_io/tribes_legacy_lookup_table.h"
-#include "sound/sound_handler.h"
+#include "sound/note_sound.h"
 
 namespace Widelands {
 
@@ -916,7 +916,7 @@
  * Whether the effect actually gets played is decided only by the sound server.
  */
 bool Worker::run_play_sound(Game& game, State& state, const Action& action) {
-	g_sound_handler.play_fx(action.sparam1, get_position(), action.iparam1);
+	Notifications::publish(NoteSound(action.sparam1, get_position(), action.iparam1));
 
 	++state.ivar1;
 	schedule_act(game, 10);

=== modified file 'src/logic/map_objects/tribes/worker_descr.cc'
--- src/logic/map_objects/tribes/worker_descr.cc	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/worker_descr.cc	2017-03-02 12:42:56 +0000
@@ -32,7 +32,6 @@
 #include "logic/map_objects/tribes/worker.h"
 #include "logic/map_objects/tribes/worker_program.h"
 #include "logic/nodecaps.h"
-#include "sound/sound_handler.h"
 
 namespace Widelands {
 

=== modified file 'src/logic/player.cc'
--- src/logic/player.cc	2017-02-27 16:49:55 +0000
+++ src/logic/player.cc	2017-03-02 12:42:56 +0000
@@ -50,7 +50,7 @@
 #include "logic/map_objects/tribes/warehouse.h"
 #include "logic/playercommand.h"
 #include "scripting/lua_table.h"
-#include "sound/sound_handler.h"
+#include "sound/note_sound.h"
 #include "wui/interactive_player.h"
 
 namespace {
@@ -278,15 +278,14 @@
 void Player::play_message_sound(const Message::Type& msgtype) {
 #define MAYBE_PLAY(type, file)                                                                     \
 	if (msgtype == type) {                                                                          \
-		g_sound_handler.play_fx(file, 200, PRIO_ALWAYS_PLAY);                                        \
+		Notifications::publish(NoteSound(file, 200, PRIO_ALWAYS_PLAY)); \
 		return;                                                                                      \
 	}
 
 	if (g_options.pull_section("global").get_bool("sound_at_message", true)) {
 		MAYBE_PLAY(Message::Type::kEconomySiteOccupied, "military/site_occupied");
 		MAYBE_PLAY(Message::Type::kWarfareUnderAttack, "military/under_attack");
-
-		g_sound_handler.play_fx("message", 200, PRIO_ALWAYS_PLAY);
+		Notifications::publish(NoteSound("message", 200, PRIO_ALWAYS_PLAY));
 	}
 }
 

=== modified file 'src/map_io/CMakeLists.txt'
--- src/map_io/CMakeLists.txt	2016-10-21 08:21:41 +0000
+++ src/map_io/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -102,6 +102,7 @@
     io_fileread
     io_filesystem
     logic
+    logic_constants
     logic_widelands_geometry
     profile
     scripting_logic

=== modified file 'src/network/CMakeLists.txt'
--- src/network/CMakeLists.txt	2016-10-21 08:21:41 +0000
+++ src/network/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -37,6 +37,7 @@
     io_filesystem
     io_stream
     logic
+    logic_constants
     logic_game_controller
     logic_game_settings
     map_io_map_loader

=== modified file 'src/notifications/note_ids.h'
--- src/notifications/note_ids.h	2017-02-22 20:23:49 +0000
+++ src/notifications/note_ids.h	2017-03-02 12:42:56 +0000
@@ -39,7 +39,8 @@
 	Building,
 	Economy,
 	GraphicResolutionChanged,
-	NoteExpeditionCanceled
+	NoteExpeditionCanceled,
+	Sound
 };
 
 #endif  // end of include guard: WL_NOTIFICATIONS_NOTE_IDS_H

=== modified file 'src/scripting/CMakeLists.txt'
--- src/scripting/CMakeLists.txt	2016-01-18 19:35:25 +0000
+++ src/scripting/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -109,6 +109,7 @@
     io_filesystem
     logic
     logic_campaign_visibility
+    logic_constants
     logic_game_controller
     logic_widelands_geometry
     map_io

=== modified file 'src/sound/CMakeLists.txt'
--- src/sound/CMakeLists.txt	2016-10-22 18:19:22 +0000
+++ src/sound/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -1,3 +1,12 @@
+wl_library(note_sound
+  SRCS
+    note_sound.h
+  DEPENDS
+    logic_widelands_geometry
+    notifications
+)
+
+
 wl_library(sound
   SRCS
     fxset.cc
@@ -16,10 +25,6 @@
     helper
     io_fileread
     io_filesystem
-    logic
-    logic_widelands_geometry
+    profile
     random
-    wui
-    wui_mapview_pixelfunctions
-    wui_mapview
 )

=== added file 'src/sound/note_sound.h'
--- src/sound/note_sound.h	1970-01-01 00:00:00 +0000
+++ src/sound/note_sound.h	2017-03-02 12:42:56 +0000
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 by the Widelands Development Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef WL_SOUND_NOTE_SOUND_H
+#define WL_SOUND_NOTE_SOUND_H
+
+#include <string>
+
+#include "logic/widelands_geometry.h"
+#include "notifications/note_ids.h"
+#include "notifications/notifications.h"
+
+struct NoteSound {
+	CAN_BE_SENT_AS_NOTE(NoteId::Sound)
+	const std::string fx;
+	const Widelands::Coords coords;
+	const uint8_t priority;
+	const uint32_t stereo_position;
+
+	NoteSound(const std::string& init_fx, Widelands::Coords init_coords, uint8_t init_priority)
+		: fx(init_fx), coords(init_coords), priority(init_priority), stereo_position(std::numeric_limits<uint32_t>::max()) {
+	}
+	NoteSound(const std::string& init_fx, uint32_t init_stereo_position, uint8_t init_priority)
+		: fx(init_fx), coords(Widelands::Coords(-1, -1)), priority(init_priority), stereo_position(init_stereo_position) {
+	}
+};
+
+#endif  // end of include guard: WL_SOUND_NOTE_SOUND_H

=== modified file 'src/sound/sound_handler.cc'
--- src/sound/sound_handler.cc	2017-01-25 18:55:59 +0000
+++ src/sound/sound_handler.cc	2017-03-02 12:42:56 +0000
@@ -36,12 +36,8 @@
 #include "helper.h"
 #include "io/fileread.h"
 #include "io/filesystem/layered_filesystem.h"
-#include "logic/game.h"
-#include "logic/map.h"
+#include "profile/profile.h"
 #include "sound/songset.h"
-#include "wui/interactive_base.h"
-#include "wui/mapview.h"
-#include "wui/mapviewpixelfunctions.h"
 
 namespace {
 
@@ -69,8 +65,7 @@
  * \sa SoundHandler::init()
 */
 SoundHandler::SoundHandler()
-   : egbase_(nullptr),
-     nosound_(false),
+	: nosound_(false),
      lock_audio_disabling_(false),
      disable_music_(false),
      disable_fx_(false),
@@ -297,30 +292,6 @@
 		    path.c_str(), fx_name.c_str(), Mix_GetError());
 }
 
-/** Calculate  the position of an effect in relation to the visible part of the
- * screen.
- * \param position  where the event happened (map coordinates)
- * \return position in widelands' game window: left=0, right=254, not in
- * viewport = -1
- * \note This function can also be used to check whether a logical coordinate is
- * visible at all
-*/
-int32_t SoundHandler::stereo_position(Widelands::Coords const position_map) {
-	if (nosound_)
-		return -1;
-
-	assert(egbase_);
-	assert(position_map);
-
-	// Viewpoint is the point of the map in pixel which is shown in the upper
-	// left corner of window or fullscreen
-	const MapView::ViewArea view_area = egbase_->get_ibase()->view_area();
-	if (!view_area.contains(position_map)) {
-		return -1;
-	}
-	const Vector2f position_pix = view_area.move_inside(position_map);
-	return static_cast<int>((position_pix.x - view_area.rect().x) * 254 / view_area.rect().w);
-}
 
 /** Find out whether to actually play a certain effect right now or rather not
  * (to avoid "sonic overload").
@@ -403,21 +374,6 @@
 	return (rng_.rand() % 255) / 255.0f <= probability;
 }
 
-/** Play (one of multiple) sound effect(s) with the given name. The effect(s)
- * must have been loaded before with \ref load_fx.
- * \param fx_name  The identifying name of the sound effect, see \ref load_fx .
- * \param map_position  Map coordinates where the event takes place
- * \param priority      How important is it that this FX actually gets played?
- *         (see \ref FXset::priority_)
-*/
-void SoundHandler::play_fx(const std::string& fx_name,
-                           Widelands::Coords const map_position,
-                           uint8_t const priority) {
-	if (nosound_)
-		return;
-	play_fx(fx_name, stereo_position(map_position), priority);
-}
-
 /** \overload
  * \param fx_name  The identifying name of the sound effect, see \ref load_fx .
  * \param stereo_position  position in widelands' game window, see

=== modified file 'src/sound/sound_handler.h'
--- src/sound/sound_handler.h	2017-01-25 18:55:59 +0000
+++ src/sound/sound_handler.h	2017-03-02 12:42:56 +0000
@@ -30,13 +30,10 @@
 #include <unistd.h>
 #endif
 
-#include "logic/widelands_geometry.h"
+
 #include "random/random.h"
 #include "sound/fxset.h"
 
-namespace Widelands {
-class EditorGameBase;
-}
 struct Songset;
 struct SDL_mutex;
 class FileRead;
@@ -184,9 +181,7 @@
 	void load_fx_if_needed(const std::string& dir,
 	                       const std::string& basename,
 	                       const std::string& fx_name);
-	void play_fx(const std::string& fx_name,
-	             Widelands::Coords map_position,
-	             uint8_t priority = PRIO_ALLOW_MULTIPLE + PRIO_MEDIUM);
+
 	void play_fx(const std::string& fx_name,
 	             int32_t stereo_position,
 	             uint8_t priority = PRIO_ALLOW_MULTIPLE + PRIO_MEDIUM);
@@ -219,11 +214,6 @@
 		return MIX_MAX_VOLUME;
 	}
 
-	/** The game logic where we can get a mapping from logical to screen
-	 * coordinates and vice vers
-	*/
-	Widelands::EditorGameBase* egbase_;
-
 	/** Only for buffering the command line option --nosound until real initialization is done.
 	 * \see SoundHandler::SoundHandler()
 	 * \see SoundHandler::init()
@@ -242,7 +232,6 @@
 	void initialization_error(const std::string& msg);
 
 	void load_one_fx(const std::string& path, const std::string& fx_name);
-	int32_t stereo_position(Widelands::Coords position);
 	bool play_or_not(const std::string& fx_name, int32_t stereo_position, uint8_t priority);
 
 	/// Whether to disable background music

=== modified file 'src/wui/CMakeLists.txt'
--- src/wui/CMakeLists.txt	2017-02-22 20:23:49 +0000
+++ src/wui/CMakeLists.txt	2017-03-02 12:42:56 +0000
@@ -258,6 +258,7 @@
     logic_game_settings
     logic_widelands_geometry
     network
+    note_sound
     notifications
     profile
     scripting_coroutine

=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc	2017-02-23 19:38:51 +0000
+++ src/wui/interactive_base.cc	2017-03-02 12:42:56 +0000
@@ -114,6 +114,14 @@
 		   resize_chat_overlay();
 		   adjust_toolbar_position();
 		});
+	sound_subscriber_ = Notifications::subscribe<NoteSound>([this](const NoteSound& note) {
+		if (note.stereo_position != std::numeric_limits<uint32_t>::max()) {
+			g_sound_handler.play_fx(note.fx, note.stereo_position, note.priority);
+		}
+		else if (note.coords != Widelands::Coords(-1, -1)) {
+			g_sound_handler.play_fx(note.fx, stereo_position(note.coords), note.priority);
+		}
+	});
 
 	toolbar_.set_layout_toplevel(true);
 	changeview.connect([this] { mainview_move(); });
@@ -614,6 +622,27 @@
 	Notifications::publish(lm);
 }
 
+/** Calculate  the position of an effect in relation to the visible part of the
+ * screen.
+ * \param position  where the event happened (map coordinates)
+ * \return position in widelands' game window: left=0, right=254, not in
+ * viewport = -1
+ * \note This function can also be used to check whether a logical coordinate is
+ * visible at all
+*/
+int32_t InteractiveBase::stereo_position(Widelands::Coords const position_map) {
+	assert(position_map);
+
+	// Viewpoint is the point of the map in pixel which is shown in the upper
+	// left corner of window or fullscreen
+	const MapView::ViewArea area = view_area();
+	if (!area.contains(position_map)) {
+		return -1;
+	}
+	const Vector2f position_pix = area.move_inside(position_map);
+	return static_cast<int>((position_pix.x - area.rect().x) * 254 / area.rect().w);
+}
+
 // Repositions the chat overlay
 void InteractiveBase::resize_chat_overlay() {
 	// 34 is the button height of the bottom menu

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2017-01-25 18:55:59 +0000
+++ src/wui/interactive_base.h	2017-03-02 12:42:56 +0000
@@ -32,6 +32,8 @@
 #include "ui_basic/box.h"
 #include "ui_basic/textarea.h"
 #include "ui_basic/unique_window.h"
+#include "sound/note_sound.h"
+#include "sound/sound_handler.h"
 #include "wui/chatoverlay.h"
 #include "wui/debugconsole.h"
 #include "wui/edge_overlay_manager.h"
@@ -211,6 +213,7 @@
 	UI::Box toolbar_;
 
 private:
+	int32_t stereo_position(Widelands::Coords position_map);
 	void resize_chat_overlay();
 	void roadb_add_overlay();
 	void roadb_remove_overlay();
@@ -242,7 +245,8 @@
 	std::unique_ptr<EdgeOverlayManager> edge_overlay_manager_;
 
 	std::unique_ptr<Notifications::Subscriber<GraphicResolutionChanged>>
-	   graphic_resolution_changed_subscriber_;
+		graphic_resolution_changed_subscriber_;
+	std::unique_ptr<Notifications::Subscriber<NoteSound>> sound_subscriber_;
 	Widelands::EditorGameBase& egbase_;
 	uint32_t display_flags_;
 	uint32_t lastframe_;        //  system time (milliseconds)


Follow ups