Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jukebox

a simple .xm music player
a simple library for loading and playing music files

supported formats: WAV, MP3, FLAC, XM
24 changes: 18 additions & 6 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
project(jukebox-app)

add_executable(jukebox)
add_library(jukebox-app)
add_library(jukebox-app::lib ALIAS jukebox-app)
Comment on lines +3 to +4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is also a library, is there no example executable anymore? What are we supposed to run after building / during development?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the executable is in app/src


target_link_libraries(jukebox
PRIVATE
jukebox::deps
target_link_libraries(jukebox-app
PUBLIC
juke::lib
)

target_sources(jukebox PRIVATE
src/main.cpp
# Glob all headers
file(GLOB_RECURSE headers "include/*.hpp")

# Set as FILE_SET, this also sets the include directory
target_sources(jukebox-app PUBLIC FILE_SET HEADERS
BASE_DIRS include
FILES ${headers}
)

# Setup our include structure
target_include_directories(jukebox-app
PRIVATE "src"
)

add_subdirectory(src)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#pragma once

#include <app/MediaPlayer.hpp>
#include <capo/engine.hpp>
#include <gvdi/context.hpp>
#include <juke/core/MediaPlayer.hpp>
#include <optional>
#include <span>

Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions app/include/app/MediaPlayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <capo/engine.hpp>
#include <juke/juke.hpp>
#include <filesystem>
#include <memory>
#include <string>

namespace juke {

class MediaPlayer {
public:
explicit MediaPlayer(capo::IEngine& audio_engine);
bool load_media(std::filesystem::path const& path);
void handle_input();

private:
Jukebox m_jukebox;
};

} // namespace juke
13 changes: 1 addition & 12 deletions library/src/core/Application.cpp → app/src/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <juke/core/Application.hpp>
#include <app/Application.hpp>
#include <stdexcept>

namespace juke {
Expand All @@ -19,19 +19,8 @@ Application::Application() {
}

void Application::run() {
using Clock = std::chrono::steady_clock;

auto now = Clock::now();

while (m_context->next_frame()) {
auto const new_now = Clock::now();
auto const dt = std::chrono::duration_cast<std::chrono::duration<float>>(new_now - now);
now = new_now;

m_player->handle_input();

m_player->update(dt);

m_context->render();
}
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

target_sources(jukebox-app PRIVATE
MediaPlayer.cpp
Application.cpp
)

add_executable(jukebox-player)

target_sources(jukebox-player PRIVATE
main.cpp
)

target_link_libraries(jukebox-player PRIVATE
jukebox-app::lib
)
43 changes: 43 additions & 0 deletions app/src/MediaPlayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#include <imgui.h>
#include <app/Colors.hpp>
#include <app/MediaPlayer.hpp>
#include <capo/engine.hpp>
#include <juke/core/AudioFile.hpp>
#include <juke/core/MediaError.hpp>
#include <juke/core/XMFile.hpp>
#include <print>

namespace juke {

using namespace std::chrono_literals;

MediaPlayer::MediaPlayer(capo::IEngine& audio_engine) : m_jukebox(audio_engine) {}

bool MediaPlayer::load_media(std::filesystem::path const& path) { return m_jukebox.load_media(path); }

void MediaPlayer::handle_input() {
ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove;
if (ImGui::Begin("Player", nullptr, flags)) {

static auto looping{true};
/* Control Buttons */
if (ImGui::Button("play")) { m_jukebox.play(looping); }
ImGui::SameLine();
if (ImGui::Button("pause")) { m_jukebox.pause(); }
ImGui::SameLine();
if (ImGui::Button("stop")) { m_jukebox.stop(); }
ImGui::SameLine();
ImGui::Checkbox("loop", &looping);
ImGui::Separator();

/* Metadata & Info */
ImGui::Text("File Name: ");
ImGui::SameLine();
m_jukebox.has_file() ? ImGui::TextColored(colors::blue, "%s", m_jukebox.get_filename().c_str()) : ImGui::TextColored(colors::grey, "<no file>");
ImGui::Text("Media Status: %s", m_jukebox.is_playing() ? "playing" : "paused");
}
ImGui::End();
}

} // namespace juke
2 changes: 1 addition & 1 deletion app/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <juke/core/Application.hpp>
#include <app/Application.hpp>
#include <print>

int main() {
Expand Down
36 changes: 0 additions & 36 deletions library/include/juke/core/MediaPlayer.hpp

This file was deleted.

43 changes: 43 additions & 0 deletions library/include/juke/juke.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#pragma once

#include <capo/engine.hpp>
#include <juke/core/MediaFile.hpp>
#include <juke/core/XMStream.hpp>
#include <filesystem>
#include <memory>

namespace juke {

class Jukebox {
public:
explicit Jukebox(capo::IEngine& audio_engine);

/// \brief Load audio file.
/// \param path Path to file.
/// \returns True if file loaded successfully, false otherwise.
bool load_media(std::filesystem::path const& path);

/// \brief Play audio.
/// \param looping Whether or not the audio loops indefinitely.
void play(bool looping = true);

/// \brief Pause audio.
void pause();

/// \brief Stop audio and set cursor to beginning. This does not work for XM format.
void stop();

/// \brief Get the name of the loaded file as a string.
[[nodiscard]] auto get_filename() const& -> std::string { return m_media_file->get_filename(); }

[[nodiscard]] auto has_file() const -> bool { return static_cast<bool>(m_media_file); }
[[nodiscard]] auto is_playing() const -> bool { return m_source->is_playing(); }
[[nodiscard]] auto is_stopped() const -> bool { return !is_playing(); }

private:
std::unique_ptr<IMediaFile> m_media_file{};
std::unique_ptr<capo::ISource> m_source{};
};

} // namespace juke
4 changes: 4 additions & 0 deletions library/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@

add_subdirectory(core)

target_sources(juke PRIVATE
juke.cpp
)
2 changes: 0 additions & 2 deletions library/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

target_sources(juke PRIVATE
Application.cpp
AudioFile.cpp
MediaPlayer.cpp
XMFile.cpp
XMStream.cpp
)
92 changes: 0 additions & 92 deletions library/src/core/MediaPlayer.cpp

This file was deleted.

Loading