-
Notifications
You must be signed in to change notification settings - Fork 0
create API for use in other apps #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
| 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) | ||
2 changes: 1 addition & 1 deletion
2
library/include/juke/core/Application.hpp → app/include/app/Application.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
|
|
||
| add_subdirectory(core) | ||
|
|
||
| target_sources(juke PRIVATE | ||
| juke.cpp | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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