Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2015-08-11 17:17:04 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:01:11 +0300
commitea10728f856cd9bb157e8f9d99d31b447a710edc (patch)
tree531357a2553d7c899247cdfc8c38117a73a84cc1 /routing
parent46aaa28d28af4c1097a37a0082b7f9374daa2e0f (diff)
Splitting GetRouteFollowingInfo into two functions. One for TTS string generation and another one for getting route following information.
Diffstat (limited to 'routing')
-rw-r--r--routing/routing_session.cpp26
-rw-r--r--routing/routing_session.hpp3
-rw-r--r--routing/routing_tests/turns_sound_test.cpp134
-rw-r--r--routing/turns_sound.cpp16
-rw-r--r--routing/turns_sound.hpp10
5 files changed, 103 insertions, 86 deletions
diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp
index 583247403f..bb1522c5ca 100644
--- a/routing/routing_session.cpp
+++ b/routing/routing_session.cpp
@@ -165,7 +165,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const
return m_state;
}
-void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info)
+void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info) const
{
auto formatDistFn = [](double dist, string & value, string & suffix)
{
@@ -217,10 +217,6 @@ void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info)
info.m_pedestrianDirectionPos = MercatorBounds::ToLatLon(pos);
info.m_pedestrianTurn =
(distanceToTurnMeters < kShowPedestrianTurnInMeters) ? turn.m_pedestrianTurn : turns::PedestrianDirection::None;
-
- // Voice turn notifications.
- if (m_routingSettings.m_soundDirection)
- m_turnsSound.UpdateRouteFollowingInfo(info, turn, distanceToTurnMeters);
}
else
{
@@ -229,6 +225,26 @@ void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info)
}
}
+void RoutingSession::GenerateTurnSound(vector<string> & turnNotifications)
+{
+ turnNotifications.clear();
+
+ threads::MutexGuard guard(m_routeSessionMutex);
+ UNUSED_VALUE(guard);
+ // Voice turn notifications.
+ if (!m_routingSettings.m_soundDirection)
+ return;
+
+ if (!m_route.IsValid() || !IsNavigable())
+ return;
+
+ double distanceToTurnMeters = 0.;
+ turns::TurnItem turn;
+ m_route.GetCurrentTurn(distanceToTurnMeters, turn);
+
+ m_turnsSound.UpdateRouteFollowingInfo(turn, distanceToTurnMeters, turnNotifications);
+}
+
void RoutingSession::AssignRoute(Route & route, IRouter::ResultCode e)
{
if (e != IRouter::Cancelled)
diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp
index 086d5a11f4..7d7cee6bda 100644
--- a/routing/routing_session.hpp
+++ b/routing/routing_session.hpp
@@ -77,7 +77,7 @@ public:
void Reset();
State OnLocationPositionChanged(m2::PointD const & position, location::GpsInfo const & info);
- void GetRouteFollowingInfo(location::FollowingInfo & info);
+ void GetRouteFollowingInfo(location::FollowingInfo & info) const;
void MatchLocationToRoute(location::GpsInfo & location,
location::RouteMatchingInfo & routeMatchingInfo) const;
@@ -94,6 +94,7 @@ public:
void SetTurnNotificationsUnits(routing::turns::sound::LengthUnits const & units);
void SetTurnNotificationsLocale(string const & locale);
string GetTurnNotificationsLocale() const;
+ void GenerateTurnSound(vector<string> & turnNotifications);
private:
struct DoReadyCallback
diff --git a/routing/routing_tests/turns_sound_test.cpp b/routing/routing_tests/turns_sound_test.cpp
index 96f88784c8..236dfffd5b 100644
--- a/routing/routing_tests/turns_sound_test.cpp
+++ b/routing/routing_tests/turns_sound_test.cpp
@@ -102,18 +102,18 @@ UNIT_TEST(TurnsSoundMetersTest)
turnSound.SetSpeedMetersPerSecond(30.);
TurnItem turnItem(5 /* idx */, TurnDirection::TurnRight);
- FollowingInfo followInfo;
+ vector<string> turnNotifications;
- ASSERT(followInfo.m_turnNotifications.empty(), ());
+ ASSERT(turnNotifications.empty(), ());
// Starting nearing the turnItem.
// 1000 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 1000. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 1000. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 700 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 700. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 700. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 699 meters till the turn. It's time to pronounce the first voice notification.
// Why? The current speed is 30 meters per seconds. According to correctSettingsMeters
@@ -121,43 +121,43 @@ UNIT_TEST(TurnsSoundMetersTest)
// Besides that we need 5 seconds (but 100 meters maximum) for playing the notification.
// So we start playing the first notification when the distance till the turn is less
// then 20 seconds * 30 meters per seconds + 100 meters = 700 meters.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 699. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem, 699. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification1 = {{"In 600 meters. Make a right turn."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ());
+ TEST_EQUAL(turnNotifications, expectedNotification1, ());
// 650 meters till the turn. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 650. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 650. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
turnSound.SetSpeedMetersPerSecond(32.);
// 150 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 150. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 150. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 100 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 100. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 100. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 99 meters till the turn. It's time to pronounce the second voice notification.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem, 99. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification2 = {{"Make a right turn."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ());
+ TEST_EQUAL(turnNotifications, expectedNotification2, ());
// 99 meters till the turn again. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 99. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 50 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 50. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 50. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 0 meters till the turn. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 0. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 0. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
TEST(turnSound.IsEnabled(), ());
}
@@ -184,48 +184,48 @@ UNIT_TEST(TurnsSoundMetersTwoTurnsTest)
turnSound.SetSpeedMetersPerSecond(35.);
TurnItem turnItem1(5 /* idx */, TurnDirection::TurnSharpRight);
- FollowingInfo followInfo;
+ vector<string> turnNotifications;
- ASSERT(followInfo.m_turnNotifications.empty(), ());
+ ASSERT(turnNotifications.empty(), ());
// Starting nearing the first turn.
// 800 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 800. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem1, 800. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 700 meters till the turn. It's time to pronounce the first voice notification.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 700. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem1, 700. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification1 = {{"In 700 meters. Make a sharp right turn."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ());
+ TEST_EQUAL(turnNotifications, expectedNotification1, ());
turnSound.SetSpeedMetersPerSecond(32.);
// 150 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 150. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem1, 150. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 99 meters till the turn. It's time to pronounce the second voice notification.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 99. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem1, 99. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification2 = {{"Make a sharp right turn."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ());
+ TEST_EQUAL(turnNotifications, expectedNotification2, ());
turnSound.SetSpeedMetersPerSecond(10.);
// 0 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 0. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem1, 0. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
TurnItem turnItem2(11 /* idx */, TurnDirection::EnterRoundAbout, 2 /* exitNum */);
// Starting nearing the second turn.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem2, 60. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem2, 60. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 40 meters till the second turn. It's time to pronounce the second voice notification
// without the first one.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem2, 40. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem2, 40. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification3 = {{"Enter the roundabout."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification3, ());
+ TEST_EQUAL(turnNotifications, expectedNotification3, ());
TEST(turnSound.IsEnabled(), ());
}
@@ -247,18 +247,18 @@ UNIT_TEST(TurnsSoundFeetTest)
turnSound.SetSpeedMetersPerSecond(30.);
TurnItem turnItem(7 /* idx */, TurnDirection::EnterRoundAbout, 3 /* exitNum */);
- FollowingInfo followInfo;
+ vector<string> turnNotifications;
- ASSERT(followInfo.m_turnNotifications.empty(), ());
+ ASSERT(turnNotifications.empty(), ());
// Starting nearing the turnItem.
// 1000 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 1000. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 1000. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 700 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 700. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 700. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 699 meters till the turn. It's time to pronounce the first voice notification.
// Why? The current speed is 30 meters per seconds. According to correctSettingsMeters
@@ -266,42 +266,42 @@ UNIT_TEST(TurnsSoundFeetTest)
// Besides that we need 5 seconds (but 100 meters maximum) for playing the notification.
// So we start playing the first notification when the distance till the turn is less
// then 20 seconds * 30 meters per seconds + 100 meters = 700 meters.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 699. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem, 699. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification1 = {{"In 2000 feet. Enter the roundabout."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ());
+ TEST_EQUAL(turnNotifications, expectedNotification1, ());
// 650 meters till the turn. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 650. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 650. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 150 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 150. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 150. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 100 meters till the turn. No sound notifications is required.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 100. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnSound.UpdateRouteFollowingInfo(turnItem, 100. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 99 meters till the turn. It's time to pronounce the second voice notification.
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */);
+ turnSound.UpdateRouteFollowingInfo(turnItem, 99. /* distanceToTurnMeters */, turnNotifications);
vector<string> const expectedNotification2 = {{"Enter the roundabout."}};
- TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ());
+ TEST_EQUAL(turnNotifications, expectedNotification2, ());
// 99 meters till the turn again. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 99. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 50 meters till the turn. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 50. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 50. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
// 0 meters till the turn. No sound notifications is required.
- followInfo.m_turnNotifications.clear();
- turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 0. /* distanceToTurnMeters */);
- TEST(followInfo.m_turnNotifications.empty(), ());
+ turnNotifications.clear();
+ turnSound.UpdateRouteFollowingInfo(turnItem, 0. /* distanceToTurnMeters */, turnNotifications);
+ TEST(turnNotifications.empty(), ());
TEST(turnSound.IsEnabled(), ());
}
diff --git a/routing/turns_sound.cpp b/routing/turns_sound.cpp
index 447a5e2085..abdbf8e1ba 100644
--- a/routing/turns_sound.cpp
+++ b/routing/turns_sound.cpp
@@ -44,10 +44,10 @@ string TurnsSound::GenerateTurnText(uint32_t distanceUnits, uint8_t exitNum, boo
return m_getTtsText(notification);
}
-void TurnsSound::UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnItem const & turn,
- double distanceToTurnMeters)
+void TurnsSound::UpdateRouteFollowingInfo(TurnItem const & turn, double distanceToTurnMeters,
+ vector<string> & turnNotifications)
{
- info.m_turnNotifications.clear();
+ turnNotifications.clear();
if (!m_enabled)
return;
@@ -76,10 +76,10 @@ void TurnsSound::UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnIt
// First turn sound notification.
uint32_t const distToPronounce =
m_settings.RoundByPresetSoundedDistancesUnits(turnNotificationDistUnits);
- info.m_turnNotifications.emplace_back(GenerateTurnText(distToPronounce, turn.m_exitNum, false, turn.m_turn,
- m_settings.GetLengthUnits()));
+ turnNotifications.emplace_back(GenerateTurnText(distToPronounce, turn.m_exitNum, false, turn.m_turn,
+ m_settings.GetLengthUnits()));
// @TODO(vbykoianko) Check if there's a turn immediately after the current turn.
- // If so add an extra item to info.m_turnNotifications with "then parameter".
+ // If so add an extra item to turnNotifications with "then parameter".
m_nextTurnNotificationProgress = PronouncedNotification::First;
}
}
@@ -95,11 +95,11 @@ void TurnsSound::UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnIt
if (m_nextTurnNotificationProgress == PronouncedNotification::First &&
distanceToTurnMeters < distanceToPronounceNotificationMeters)
{
- info.m_turnNotifications.emplace_back(GenerateTurnText(0, turn.m_exitNum, false, turn.m_turn,
+ turnNotifications.emplace_back(GenerateTurnText(0, turn.m_exitNum, false, turn.m_turn,
m_settings.GetLengthUnits()));
// @TODO(vbykoianko) Check if there's a turn immediately after the current turn.
- // If so add an extra item to info.m_turnNotifications with "then parameter".
+ // If so add an extra item to info.turnNotifications with "then parameter".
m_nextTurnNotificationProgress = PronouncedNotification::Second;
}
}
diff --git a/routing/turns_sound.hpp b/routing/turns_sound.hpp
index 49b760f7a5..41a2c6057e 100644
--- a/routing/turns_sound.hpp
+++ b/routing/turns_sound.hpp
@@ -72,14 +72,14 @@ public:
void SetSpeedMetersPerSecond(double speed);
/// \brief UpdateRouteFollowingInfo updates information about the next turn notification.
- /// It also fills FollowingInfo::m_turnNotifications when it's necessary.
+ /// It also fills turnNotifications when it's necessary.
/// If this TurnsSound wants to play a sound message once it should push one item to
- /// the vector FollowingInfo::m_turnNotifications once when UpdateRouteFollowingInfo is called.
- /// \param info is a parameter to fill info.m_turnNotifications
+ /// the vector turnNotifications once when UpdateRouteFollowingInfo is called.
/// \param turn contains information about the next turn.
/// \param distanceToTurnMeters is distance to the next turn in meters.
- void UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnItem const & turn,
- double distanceToTurnMeters);
+ /// \param turnNotifications is a parameter to fill it if it's necessary.
+ void UpdateRouteFollowingInfo(TurnItem const & turn, double distanceToTurnMeters,
+ vector<string> & turnNotifications);
/// Reset states which reflects current route position.
/// The method shall be called after creating a new route or after rerouting.
void Reset();