Skip to content

Commit

Permalink
✨ [Player] set_time now returns a bool to indicate if the time has ac…
Browse files Browse the repository at this point in the history
…tually changed
  • Loading branch information
JulesFouchy committed Dec 9, 2023
1 parent 93003b7 commit e4e8303
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ void Player::pause()
_is_playing = false;
}

void Player::set_time(float time_in_seconds)
auto Player::set_time(float time_in_seconds) -> bool
{
_next_frame_to_play = static_cast<int64_t>(
auto const next_frame_to_play = static_cast<int64_t>(
static_cast<float>(_data.sample_rate)
* time_in_seconds
);
bool const has_changed = next_frame_to_play != _next_frame_to_play;
_next_frame_to_play = next_frame_to_play;
return has_changed;
}

auto Player::get_time() const -> float
Expand Down
3 changes: 2 additions & 1 deletion src/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class Player {
///
[[nodiscard]] auto is_playing() const -> bool { return _is_playing; }
/// Makes the player jump to a specific moment in time.
void set_time(float time_in_seconds);
/// Return true iff the time has actually changed (i.e. the time that was passed to the function is different from the time that was currently set).
auto set_time(float time_in_seconds) -> bool;
/// Returns the moment in time the player is currently playing.
[[nodiscard]] auto get_time() const -> float;

Expand Down

0 comments on commit e4e8303

Please sign in to comment.