Refactor!
This commit is contained in:
parent
5d7a343a20
commit
a5f4d7149a
14 changed files with 13024 additions and 1920 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "LibraryViewer.hpp"
|
||||
#include "WavPlayer.hpp"
|
||||
#include "Library.hpp"
|
||||
#include "Player.hpp"
|
||||
#include "Rect.hpp"
|
||||
#include "Animations.hpp"
|
||||
#include "imgui.h"
|
||||
|
|
@ -96,25 +96,34 @@ public:
|
|||
void RenderUI() {
|
||||
ImGui::Begin("InfoWindow", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize);
|
||||
|
||||
if (mTrack && ImGui::Button("load")) {
|
||||
mLoadStatus = mPlayer->startStreamTrack(mTrack->mId);
|
||||
}
|
||||
if (mTrack) {
|
||||
|
||||
ImGui::SameLine(); ImGui::Text(" Load Status : %s", mLoadStatus ? "Loaded" : "Not Loaded");
|
||||
ImGui::Text(" Load Status : %s", mLoadStatus ? "Loaded" : "Not Loaded");
|
||||
|
||||
if (mTrack && mLoadStatus) {
|
||||
auto songProgress = mPlayer->getProgress();
|
||||
ImGui::SliderFloat("Progress", &songProgress, 0.f, 1.f);
|
||||
mPlayer->setProgress(songProgress);
|
||||
}
|
||||
if (ImGui::Button("Play")) {
|
||||
if (mPlayer->getPlayingId() != mTrack->mId) {
|
||||
mLoadStatus = mPlayer->startStreamTrack(mTrack->mId);
|
||||
}
|
||||
mPlayer->continuePlayback();
|
||||
}
|
||||
|
||||
if (ImGui::Button("Play")) {
|
||||
mPlayer->playSong();
|
||||
}
|
||||
if (mLoadStatus) {
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Stop")) {
|
||||
mPlayer->stopSong();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Stop")) {
|
||||
mPlayer->freezePlayback();
|
||||
}
|
||||
|
||||
auto songProgress = mPlayer->getPlaybackProgress();
|
||||
auto vol = mPlayer->getVolume();
|
||||
ImGui::Text("Load Progress : %f", mPlayer->getLoadProgress());
|
||||
if (ImGui::SliderFloat("Progress", &songProgress, 0.f, 1.f)) {
|
||||
mPlayer->setPlaybackProgress(songProgress);
|
||||
}
|
||||
if (ImGui::SliderFloat("Volume", &vol, 0.f, 1.f)) {
|
||||
mPlayer->setVolume(vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Text("Song Info:");
|
||||
|
|
@ -137,6 +146,10 @@ public:
|
|||
if (ImGui::Checkbox("Loved only", &filterLoved)) {
|
||||
isSongFilterChanged |= true;
|
||||
}
|
||||
|
||||
if (ImGui::SliderInt("Existing only", &filterExisting, 0, 3)) {
|
||||
isSongFilterChanged |= true;
|
||||
}
|
||||
|
||||
isSongFilterChanged |= songFilter.Draw("Song Filter");
|
||||
|
||||
|
|
@ -170,9 +183,10 @@ public:
|
|||
tp::Buffer<SortType> items;
|
||||
const Track* mTrack;
|
||||
bool filterLoved = false;
|
||||
TrackPlayer* mPlayer = nullptr;
|
||||
Player* mPlayer = nullptr;
|
||||
bool mLoadStatus = false;
|
||||
bool isSongFilterChanged = true;
|
||||
int filterExisting = 0; // all existing no-existing
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -300,7 +314,7 @@ public:
|
|||
template <typename Events, typename Canvas> requires(DrawableConcept<Canvas>)
|
||||
class LibraryWidget {
|
||||
public:
|
||||
LibraryWidget(Library* lib, TrackPlayer* player) : mLibrary(lib), mPlayer(player) {
|
||||
LibraryWidget(Library* lib, Player* player) : mLibrary(lib), mPlayer(player) {
|
||||
for (auto track : mLibrary->mTraks) {
|
||||
mTraks.append(TrackWidget<Events, Canvas>(&track.data()));
|
||||
}
|
||||
|
|
@ -358,7 +372,9 @@ public:
|
|||
auto idx = 0;
|
||||
|
||||
for (auto track : mTraksFiltered) {
|
||||
track->draw(canvas, area, { area.x + 10, area.y + 10 + idx * trackSize - offset, area.z - 20 - scrollSize, trackSize - 5 } );
|
||||
auto const trackArea = tp::RectF{ area.x + 10, area.y + 10 + idx * trackSize - offset, area.z - 20 - scrollSize, trackSize - 5 };
|
||||
if (track->mTrack == mCurrentTrack.mTrack) canvas.rect(trackArea, { 0.2f, 0.2f, 0.2f, 0.5f }, 5);
|
||||
track->draw(canvas, area, trackArea);
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
|
@ -390,6 +406,16 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
switch (mCurrentTrackInfo.filterExisting) {
|
||||
case 1:
|
||||
if (!track->mTrack->mExists) continue;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (track->mTrack->mExists) continue;
|
||||
break;
|
||||
}
|
||||
|
||||
mTraksFiltered.append( &track.data() );
|
||||
}
|
||||
|
||||
|
|
@ -419,7 +445,7 @@ private:
|
|||
ResizerWidget<Events, Canvas> mResizeWidget;
|
||||
|
||||
Library* mLibrary;
|
||||
TrackPlayer* mPlayer;
|
||||
Player* mPlayer;
|
||||
|
||||
bool mNeedRedraw = false;
|
||||
};
|
||||
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
#include "Window.hpp"
|
||||
|
||||
typedef tp::ualni SongId;
|
||||
enum class SONG_FORMAT { WAV, FLAC, NONE };
|
||||
|
||||
tp::String getHome();
|
||||
tp::String getSongLocalPath(SongId id);
|
||||
SONG_FORMAT getSongFormat(const tp::String& path);
|
||||
|
||||
namespace tp {
|
||||
extern ModuleManifest gModuleLibraryViewer;
|
||||
|
|
@ -13,7 +18,7 @@ public:
|
|||
Track() = default;
|
||||
|
||||
public:
|
||||
tp::ualni mId = 0;
|
||||
SongId mId = 0;
|
||||
tp::String mName = "undef";
|
||||
tp::String mArtist = "undef";
|
||||
tp::String mAlbumArtist = "undef";
|
||||
|
|
@ -36,20 +41,7 @@ public:
|
|||
bool mLoved = false;
|
||||
bool mAlbumLoved = false;
|
||||
bool mExplicit = false;
|
||||
// tp::String mKind = "undef";
|
||||
// tp::ualni mDiscNumber = 0;
|
||||
// tp::ualni mDiscCount = 0;
|
||||
// tp::ualni mTrackNumber = 0;
|
||||
// tp::ualni mTrackCount = 0;
|
||||
// tp::ualni mBitRate = 0;
|
||||
// tp::ualni mSampleRate = 0;
|
||||
// tp::ualni Compilation
|
||||
// tp::ualni Artwork Count
|
||||
// tp::ualni Sort Album
|
||||
// tp::ualni Sort Artist
|
||||
// tp::ualni Sort Name
|
||||
// tp::ualni Persistent ID
|
||||
// tp::ualni Track Type
|
||||
bool mExists = false;
|
||||
};
|
||||
|
||||
class Library {
|
||||
|
|
@ -58,11 +50,8 @@ public:
|
|||
|
||||
public:
|
||||
bool loadJson(const tp::String& path);
|
||||
void checkExisting();
|
||||
|
||||
public:
|
||||
tp::Buffer<Track> mTraks;
|
||||
};
|
||||
|
||||
class LibraryViewverGui {};
|
||||
|
||||
void runApp();
|
||||
};
|
||||
32
LibraryViewer/public/Player.hpp
Normal file
32
LibraryViewer/public/Player.hpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "Library.hpp"
|
||||
#include "Streamer.hpp"
|
||||
|
||||
class DeviceStream;
|
||||
|
||||
class Player {
|
||||
public:
|
||||
Player();
|
||||
~Player();
|
||||
|
||||
bool startStreamTrack(SongId id);
|
||||
SongId getPlayingId() const;
|
||||
void continuePlayback();
|
||||
void freezePlayback();
|
||||
|
||||
tp::halnf getDurationSec() const;
|
||||
|
||||
void setVolume(tp::halnf volume);
|
||||
tp::halnf getVolume();
|
||||
|
||||
tp::halnf getPlaybackProgress() const;
|
||||
void setPlaybackProgress(tp::halnf newProgress);
|
||||
|
||||
tp::halnf getLoadProgress() const;
|
||||
|
||||
private:
|
||||
SongId connected = 0;
|
||||
MusicStream mMusicStream;
|
||||
DeviceStream* mDeviceStream;
|
||||
};
|
||||
34
LibraryViewer/public/Streamer.hpp
Normal file
34
LibraryViewer/public/Streamer.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include "Library.hpp"
|
||||
|
||||
class Context;
|
||||
|
||||
class MusicStream {
|
||||
friend Context;
|
||||
|
||||
public:
|
||||
MusicStream();
|
||||
~MusicStream();
|
||||
|
||||
bool openStream(SongId id);
|
||||
void closeStream();
|
||||
|
||||
tp::halnf* getBuffer();
|
||||
tp::ualni* getProgressLive();
|
||||
tp::uhalni getRate() const;
|
||||
|
||||
void continueStream();
|
||||
tp::ualni getFramesLength() const;
|
||||
tp::ualni getFramesLoaded() const;
|
||||
|
||||
public:
|
||||
class Context* mContext = nullptr;
|
||||
// tp::Mutex mMutex;
|
||||
|
||||
tp::ualni mLengthFrames = 0;
|
||||
tp::ualni mChanels = 0;
|
||||
tp::ualni mRate = 0;
|
||||
tp::ualni mProgress;
|
||||
tp::Buffer<tp::halnf> mBuffer;
|
||||
};
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "LibraryViewer.hpp"
|
||||
|
||||
class MusicPlayerContext;
|
||||
typedef tp::ualni SongId;
|
||||
|
||||
class TrackPlayer {
|
||||
public:
|
||||
TrackPlayer();
|
||||
~TrackPlayer();
|
||||
|
||||
bool startStreamTrack(SongId id);
|
||||
|
||||
void playSong();
|
||||
|
||||
void stopSong();
|
||||
|
||||
void setVolume(float volume);
|
||||
|
||||
float getProgress() const;
|
||||
|
||||
float getDurationSec() const;
|
||||
|
||||
void setProgress(float newProgress);
|
||||
|
||||
private:
|
||||
MusicPlayerContext* mContext;
|
||||
};
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue