uh lets ignore that I did the last commits from the wrong folder
This commit is contained in:
0
src/Public/Layouts/QOverlayout.cpp
Normal file → Executable file
0
src/Public/Layouts/QOverlayout.cpp
Normal file → Executable file
0
src/Public/Layouts/QOverlayout.h
Normal file → Executable file
0
src/Public/Layouts/QOverlayout.h
Normal file → Executable file
22
src/Public/MainWindow.cpp
Normal file → Executable file
22
src/Public/MainWindow.cpp
Normal file → Executable file
@@ -1,15 +1,8 @@
|
||||
#include <QtWidgets>
|
||||
#include <QLayout>
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "Modules/FloatingControls/FloatingControls.h"
|
||||
#include "Layouts/QOverlayout.h"
|
||||
#include "Pages/pages.h"
|
||||
#include "Pages/Playlist/PlaylistPage.h"
|
||||
#include "Widgets/Playlist/PlaylistWidget.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
void MainWindow::setupMainWindow( ) {
|
||||
this->setWindowTitle("Crylia Player");
|
||||
this->setWindowIcon(QIcon(":aqua.jpg"));
|
||||
|
||||
QWidget* mw = new QWidget(this);
|
||||
mw->setContentsMargins(10, 10, 10, 10);
|
||||
@@ -20,7 +13,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
Pages* p = new Pages(mw);
|
||||
PlaylistPage* pp = new PlaylistPage(mw);
|
||||
PlaylistWidget* pw = new PlaylistWidget(mw);
|
||||
FloatingControls* fc = new FloatingControls(mw);
|
||||
FloatingControls* fc = new FloatingControls(mw, this->path);
|
||||
|
||||
QVBoxLayout* vbox = new QVBoxLayout( );
|
||||
vbox->addWidget(fc, 0, Qt::AlignBottom);
|
||||
@@ -41,4 +34,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
this->setCentralWidget(mw);
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
setupMainWindow( );
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(std::filesystem::path path, QWidget* parent)
|
||||
: QMainWindow(parent), path(path) {
|
||||
setupMainWindow( );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow( ) { }
|
||||
|
||||
20
src/Public/MainWindow.h
Normal file → Executable file
20
src/Public/MainWindow.h
Normal file → Executable file
@@ -1,15 +1,29 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QtWidgets>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLayout>
|
||||
#include <QPixmap>
|
||||
#include <filesystem>
|
||||
|
||||
#include "Modules/FloatingControls/FloatingControls.h"
|
||||
#include "Layouts/QOverlayout.h"
|
||||
#include "Modules/PageNavigator/pages.h"
|
||||
#include "Pages/Playlist/PlaylistPage.h"
|
||||
#include "Modules/PlaylistNavigator/PlaylistWidget.h"
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget* parent = nullptr);
|
||||
MainWindow(std::filesystem::path path, QWidget* parent = nullptr);
|
||||
~MainWindow( );
|
||||
|
||||
private:
|
||||
// In case the program gets started with a song as an argument
|
||||
std::filesystem::path path;
|
||||
|
||||
void setupMainWindow( );
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
95
src/Public/Modules/FloatingControls/FloatingControls.cpp
Normal file → Executable file
95
src/Public/Modules/FloatingControls/FloatingControls.cpp
Normal file → Executable file
@@ -61,7 +61,7 @@ static QPushButton* makeSongControlButton(QString name, QSize size = QSize(36, 3
|
||||
return button;
|
||||
}
|
||||
|
||||
FloatingControls::FloatingControls(QWidget* parent) :
|
||||
FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path) :
|
||||
QFrame(parent),
|
||||
volume(100),
|
||||
albumArtPath("default.png"),
|
||||
@@ -69,8 +69,8 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
playPause(false),
|
||||
songRepeat(NONE),
|
||||
artist("Artist"),
|
||||
songName("Song") {
|
||||
|
||||
songName("Song"),
|
||||
song(Audio::getInstance(path)) {
|
||||
this->setFixedHeight(100);
|
||||
this->setObjectName("main");
|
||||
this->setStyleSheet(R"(
|
||||
@@ -85,7 +85,6 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
|
||||
/* Main Layout to store the Left Center and right controls */
|
||||
QHBoxLayout* mainLayout = new QHBoxLayout(this);
|
||||
|
||||
/* Left side Icon, Artist and Song info */
|
||||
QHBoxLayout* leftLayout = new QHBoxLayout( );
|
||||
leftLayout->setSpacing(10);
|
||||
@@ -102,12 +101,13 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
}
|
||||
)");
|
||||
//! Change later to the actual album art when the controls are done
|
||||
albumArt->setPixmap(QPixmap(":aqua.jpg").scaled(QSize(64, 64), Qt::IgnoreAspectRatio));
|
||||
albumArt->setPixmap(song.GetAlbumCover( ).scaled(QSize(64, 64), Qt::IgnoreAspectRatio));
|
||||
leftLayout->addWidget(albumArt);
|
||||
|
||||
// Artist and Song name layout
|
||||
QVBoxLayout* artistSongLayout = new QVBoxLayout( );
|
||||
QLabel* artist = new QLabel(getArtist( ));
|
||||
QLabel* artist = new QLabel(QString::fromStdString(song.GetArtist( )));
|
||||
artist->setMinimumWidth(50);
|
||||
connect(this, &FloatingControls::artistChanged, artist, &QLabel::setText);
|
||||
artist->setObjectName("artist");
|
||||
artist->setStyleSheet(R"(
|
||||
@@ -118,9 +118,13 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
}
|
||||
)");
|
||||
|
||||
QLabel* songName = new QLabel(getSongName( ));
|
||||
QLabel* songName = new QLabel( );
|
||||
songName->setMinimumWidth(50);
|
||||
QFontMetrics metrics(songName->font( ));
|
||||
songName->setText(metrics.elidedText(QString::fromStdString(song.GetTitle( )), Qt::ElideRight, songName->width( )));
|
||||
|
||||
connect(this, &FloatingControls::songNameChanged, songName, &QLabel::setText);
|
||||
songName->setObjectName("songName");
|
||||
songName->setObjectName("title");
|
||||
songName->setStyleSheet(R"(
|
||||
QLabel#songName{
|
||||
font-size: 14px;
|
||||
@@ -135,6 +139,9 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
QVBoxLayout* centerLayout = new QVBoxLayout( );
|
||||
centerLayout->setAlignment(Qt::AlignCenter);
|
||||
|
||||
mainLayout->setStretchFactor(leftLayout, 1);
|
||||
mainLayout->setStretchFactor(centerLayout, 0.1);
|
||||
|
||||
QHBoxLayout* songControlsLayout = new QHBoxLayout( );
|
||||
songControlsLayout->setAlignment(Qt::AlignCenter | Qt::AlignBottom);
|
||||
|
||||
@@ -145,10 +152,31 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
col = "#CC79AB";
|
||||
else
|
||||
col = "#D7D7D7";
|
||||
QPushButton* pb = makeSongControlButton(buttonNames[i], QSize(36, 36), col);
|
||||
if (buttonNames[i] == "play") {
|
||||
//TODO Change later
|
||||
QObject::connect(pb, &QPushButton::clicked, [pb, this]( ) {
|
||||
if (!song.IsMusicPlaying( )) {
|
||||
song.StartMusic( );
|
||||
pb->setIcon(RenderSvg(":/icons/songControl/pause.svg"));
|
||||
return;
|
||||
}
|
||||
if (GetPlayPause( )) {
|
||||
song.ResumeMusic( );
|
||||
pb->setIcon(RenderSvg(":/icons/songControl/pause.svg"));
|
||||
}
|
||||
else {
|
||||
song.PauseMusic( );
|
||||
pb->setIcon(RenderSvg(":/icons/songControl/play.svg"));
|
||||
}
|
||||
togglePlayPause( );
|
||||
});
|
||||
}
|
||||
songControlsLayout->addWidget(pb);
|
||||
|
||||
songControlsLayout->addWidget(makeSongControlButton(buttonNames[i], QSize(36, 36), col));
|
||||
}
|
||||
|
||||
|
||||
centerLayout->addLayout(songControlsLayout);
|
||||
|
||||
QHBoxLayout* songScrollerLayout = new QHBoxLayout( );
|
||||
@@ -156,6 +184,12 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
|
||||
// Song timestamp
|
||||
QLabel* songTimestamp = new QLabel("00:00");
|
||||
songTimestamp->setText(
|
||||
QTime(
|
||||
0,
|
||||
song.GetMusicPos( ) / 60,
|
||||
song.GetMusicPos( ) % 60
|
||||
).toString("mm:ss"));
|
||||
songTimestamp->setObjectName("songTimestamp");
|
||||
songTimestamp->setStyleSheet(R"(
|
||||
QLabel#songTimestamp{
|
||||
@@ -167,6 +201,12 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
|
||||
// Song duration
|
||||
QLabel* songDuration = new QLabel("00:00");
|
||||
songDuration->setText(
|
||||
QTime(
|
||||
0,
|
||||
song.GetMusicDuration( ) / 60,
|
||||
song.GetMusicDuration( ) % 60
|
||||
).toString("mm:ss"));
|
||||
songDuration->setObjectName("songDuration");
|
||||
songDuration->setStyleSheet(R"(
|
||||
QLabel#songDuration{
|
||||
@@ -178,9 +218,8 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
// Song duration slider
|
||||
QSlider* songDurationSlider = new QSlider(Qt::Horizontal);
|
||||
songDurationSlider->setObjectName("songDurationSlider");
|
||||
songDurationSlider->setRange(0, 100);
|
||||
songDurationSlider->setValue(50);
|
||||
songDurationSlider->setFixedWidth(480);
|
||||
songDurationSlider->setRange(0, song.GetMusicDuration( ));
|
||||
songDurationSlider->setValue(song.GetMusicPos( ));
|
||||
songDurationSlider->setFixedHeight(28);
|
||||
songDurationSlider->setStyleSheet(R"(
|
||||
QSlider#songDurationSlider::groove:horizontal{
|
||||
@@ -204,10 +243,32 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
}
|
||||
)");
|
||||
songDurationSlider->setCursor(Qt::PointingHandCursor);
|
||||
|
||||
connect(songDurationSlider, &QSlider::sliderReleased, [this, songDurationSlider]( ) {
|
||||
song.SetMusicPos(songDurationSlider->value( ));
|
||||
});
|
||||
|
||||
songScrollerLayout->addWidget(songTimestamp);
|
||||
songScrollerLayout->addWidget(songDurationSlider);
|
||||
songScrollerLayout->addWidget(songDuration);
|
||||
|
||||
QTimer* timer = new QTimer(this);
|
||||
|
||||
connect(timer, &QTimer::timeout, this, [this, songTimestamp, songDurationSlider]( ) {
|
||||
int sec = song.GetMusicPos( );
|
||||
|
||||
songTimestamp->setText(
|
||||
QTime(
|
||||
0,
|
||||
sec / 60,
|
||||
sec % 60
|
||||
).toString("mm:ss"));
|
||||
|
||||
songDurationSlider->setValue(sec);
|
||||
//std::cout << songTimestamp->text( ).toStdString( ) << std::endl;
|
||||
});
|
||||
timer->start(1000);
|
||||
|
||||
centerLayout->addLayout(songScrollerLayout);
|
||||
|
||||
/* Right side layout to store the volume and fullscreen controls */
|
||||
@@ -228,9 +289,8 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
//Volume slider
|
||||
QSlider* VolumeSlider = new QSlider(Qt::Horizontal);
|
||||
VolumeSlider->setObjectName("volumeSlider");
|
||||
VolumeSlider->setRange(0, 100);
|
||||
VolumeSlider->setValue(volume);
|
||||
VolumeSlider->setFixedWidth(150);
|
||||
VolumeSlider->setRange(0, 128);
|
||||
VolumeSlider->setValue(song.GetVolume( ));
|
||||
VolumeSlider->setFixedHeight(28);
|
||||
VolumeSlider->setStyleSheet(R"(
|
||||
QSlider#volumeSlider::groove:horizontal{
|
||||
@@ -254,6 +314,11 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
||||
}
|
||||
)");
|
||||
VolumeSlider->setCursor(Qt::PointingHandCursor);
|
||||
|
||||
connect(VolumeSlider, &QSlider::valueChanged, [this, VolumeSlider]( ) {
|
||||
song.SetVolume(VolumeSlider->value( ));
|
||||
});
|
||||
|
||||
rightLayout->addWidget(VolumeSlider);
|
||||
|
||||
//Fullscreen button
|
||||
|
||||
29
src/Public/Modules/FloatingControls/FloatingControls.h
Normal file → Executable file
29
src/Public/Modules/FloatingControls/FloatingControls.h
Normal file → Executable file
@@ -1,9 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../core/audio/audio.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QSlider>
|
||||
#include <QPushButton>
|
||||
#include <QObject>
|
||||
#include <filesystem>
|
||||
|
||||
enum Repeat : short;
|
||||
|
||||
@@ -13,6 +16,7 @@ class FloatingControls : public QFrame {
|
||||
|
||||
Q_PROPERTY(QString artist READ getArtist WRITE setArtist NOTIFY artistChanged)
|
||||
Q_PROPERTY(QString songName READ getSongName WRITE setSongName NOTIFY songNameChanged)
|
||||
Q_PROPERTY(int songPos READ getSongPos WRITE setSongPos NOTIFY songPosChanged)
|
||||
public:
|
||||
|
||||
QString getArtist( ) const {
|
||||
@@ -37,12 +41,31 @@ public:
|
||||
emit songNameChanged(songName);
|
||||
}
|
||||
|
||||
FloatingControls(QWidget* parent = nullptr);
|
||||
int getSongPos( ) const {
|
||||
return songPos;
|
||||
}
|
||||
void setSongPos(int pos) {
|
||||
if (this->songPos == pos)
|
||||
return;
|
||||
this->songPos = pos;
|
||||
emit songPosChanged(pos);
|
||||
}
|
||||
|
||||
void togglePlayPause( ) {
|
||||
this->playPause = !this->playPause;
|
||||
}
|
||||
|
||||
bool GetPlayPause( ) {
|
||||
return this->playPause;
|
||||
}
|
||||
|
||||
FloatingControls(QWidget* parent = nullptr, std::filesystem::path path = std::filesystem::path( ));
|
||||
~FloatingControls( );
|
||||
|
||||
signals:
|
||||
void artistChanged(QString artist);
|
||||
void songNameChanged(QString songName);
|
||||
void songPosChanged(int songPos);
|
||||
|
||||
private:
|
||||
QString artist;
|
||||
@@ -55,4 +78,8 @@ private:
|
||||
bool playPause;
|
||||
Repeat songRepeat;
|
||||
QPixmap albumArt;
|
||||
int songPos;
|
||||
int songLength;
|
||||
|
||||
Audio& song;
|
||||
};
|
||||
|
||||
0
src/Public/Pages/pages.cpp → src/Public/Modules/PageNavigator/pages.cpp
Normal file → Executable file
0
src/Public/Pages/pages.cpp → src/Public/Modules/PageNavigator/pages.cpp
Normal file → Executable file
0
src/Public/Pages/pages.h → src/Public/Modules/PageNavigator/pages.h
Normal file → Executable file
0
src/Public/Pages/pages.h → src/Public/Modules/PageNavigator/pages.h
Normal file → Executable file
0
src/Public/Widgets/Playlist/PlaylistWidget.cpp → src/Public/Modules/PlaylistNavigator/PlaylistWidget.cpp
Normal file → Executable file
0
src/Public/Widgets/Playlist/PlaylistWidget.cpp → src/Public/Modules/PlaylistNavigator/PlaylistWidget.cpp
Normal file → Executable file
0
src/Public/Widgets/Playlist/PlaylistWidget.h → src/Public/Modules/PlaylistNavigator/PlaylistWidget.h
Normal file → Executable file
0
src/Public/Widgets/Playlist/PlaylistWidget.h → src/Public/Modules/PlaylistNavigator/PlaylistWidget.h
Normal file → Executable file
0
src/Public/Pages/Playlist/PlaylistPage.cpp
Normal file → Executable file
0
src/Public/Pages/Playlist/PlaylistPage.cpp
Normal file → Executable file
0
src/Public/Pages/Playlist/PlaylistPage.h
Normal file → Executable file
0
src/Public/Pages/Playlist/PlaylistPage.h
Normal file → Executable file
111
src/core/audio/audio.cpp
Normal file
111
src/core/audio/audio.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#include "audio.h"
|
||||
|
||||
Audio::Audio(const std::string path) :path(path) {
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
std::cerr << "SDL initialization failed: " << SDL_GetError( ) << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) == -1) {
|
||||
std::cerr << "SDL_mixer initialization failed: " << Mix_GetError( ) << std::endl;
|
||||
SDL_Quit( );
|
||||
return;
|
||||
}
|
||||
|
||||
music = Mix_LoadMUS(path.c_str( ));
|
||||
if (!music) {
|
||||
std::cerr << "Failed to load MP3 file: " << Mix_GetError( ) << std::endl;
|
||||
Mix_CloseAudio( );
|
||||
SDL_Quit( );
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Audio::~Audio( ) {
|
||||
Mix_FreeMusic(music);
|
||||
Mix_CloseAudio( );
|
||||
SDL_Quit( );
|
||||
}
|
||||
|
||||
void Audio::StartMusic( ) {
|
||||
if (Mix_PlayingMusic( ) == 0) {
|
||||
//TODO: Get the loop status from the FloatingControls widget and replace the 1
|
||||
Mix_PlayMusic(music, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::PauseMusic( ) {
|
||||
if (Mix_PlayingMusic( ) == 1) {
|
||||
Mix_PauseMusic( );
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::ResumeMusic( ) {
|
||||
if (Mix_PausedMusic( ) == 1) {
|
||||
Mix_ResumeMusic( );
|
||||
}
|
||||
}
|
||||
|
||||
bool Audio::IsMusicPlaying( ) {
|
||||
return Mix_PlayingMusic( );
|
||||
}
|
||||
|
||||
std::string Audio::GetTitle( ) {
|
||||
std::cout << Mix_GetMusicTitleTag(music) << std::endl;
|
||||
return Mix_GetMusicTitleTag(music);
|
||||
}
|
||||
|
||||
std::string Audio::GetArtist( ) {
|
||||
return Mix_GetMusicArtistTag(music);
|
||||
}
|
||||
|
||||
int Audio::GetMusicPos( ) {
|
||||
return Mix_GetMusicPosition(music);
|
||||
}
|
||||
|
||||
int Audio::SetMusicPos(int pos) {
|
||||
return Mix_SetMusicPosition(pos);
|
||||
}
|
||||
|
||||
int Audio::GetMusicDuration( ) {
|
||||
return Mix_MusicDuration(music);
|
||||
}
|
||||
|
||||
QPixmap Audio::GetAlbumCover( ) {
|
||||
AVFormatContext* fc = avformat_alloc_context( );
|
||||
if (avformat_open_input(&fc, this->path.c_str( ), NULL, NULL) != 0) {
|
||||
SDL_Log("Error opening audio file");
|
||||
return QPixmap( );
|
||||
}
|
||||
|
||||
if (avformat_find_stream_info(fc, NULL) < 0) {
|
||||
SDL_Log("Could not find stream information");
|
||||
return QPixmap( );
|
||||
}
|
||||
|
||||
AVPacket packet;
|
||||
int ret;
|
||||
|
||||
while ((ret = av_read_frame(fc, &packet)) >= 0) {
|
||||
AVStream* stream = fc->streams[packet.stream_index];
|
||||
if (stream->disposition & AV_DISPOSITION_ATTACHED_PIC) {
|
||||
return QPixmap::fromImage(QImage::fromData(reinterpret_cast<const uchar*>(packet.data), packet.size));
|
||||
}
|
||||
av_packet_unref(&packet);
|
||||
}
|
||||
|
||||
avformat_close_input(&fc);
|
||||
avformat_free_context(fc);
|
||||
|
||||
return QPixmap( );
|
||||
}
|
||||
|
||||
int Audio::GetVolume( ) {
|
||||
return Mix_GetMusicVolume(music);
|
||||
}
|
||||
|
||||
void Audio::SetVolume(int vol) {
|
||||
if (vol > MIX_MAX_VOLUME)
|
||||
vol = MIX_MAX_VOLUME;
|
||||
Mix_VolumeMusic(vol);
|
||||
}
|
||||
53
src/core/audio/audio.h
Normal file
53
src/core/audio/audio.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <string>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Audio {
|
||||
public:
|
||||
static Audio& getInstance(const std::string path) {
|
||||
static Audio instance(path);
|
||||
return instance;
|
||||
}
|
||||
private:
|
||||
Audio(const std::string path);
|
||||
|
||||
const std::string path;
|
||||
const std::string artist;
|
||||
const std::string album;
|
||||
|
||||
Mix_Music* music;
|
||||
|
||||
public:
|
||||
~Audio( );
|
||||
|
||||
Audio(Audio const&) = delete;
|
||||
void operator=(Audio const&) = delete;
|
||||
|
||||
std::string GetTitle( );
|
||||
std::string GetArtist( );
|
||||
std::string GetAlbum( );
|
||||
|
||||
int GetMusicPos( );
|
||||
int GetMusicDuration( );
|
||||
int SetMusicPos(int pos);
|
||||
|
||||
QPixmap GetAlbumCover( );
|
||||
|
||||
void StartMusic( );
|
||||
void PauseMusic( );
|
||||
void ResumeMusic( );
|
||||
bool IsMusicPlaying( );
|
||||
|
||||
void SetVolume(int vol);
|
||||
int GetVolume( );
|
||||
};
|
||||
22
src/main.cpp
Normal file → Executable file
22
src/main.cpp
Normal file → Executable file
@@ -1,10 +1,28 @@
|
||||
#include "Public/MainWindow.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <QApplication>
|
||||
#include <iostream>
|
||||
|
||||
bool CheckValidFile(std::filesystem::path path) {
|
||||
//Allow to start with a song
|
||||
if (!std::filesystem::exists(path) || !std::filesystem::is_regular_file(path)) {
|
||||
std::cerr << "ERROR: Path or file doesn't exist / is valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::string extension = path.extension( ).string( );
|
||||
if (!(extension == ".mp3" || extension == ".flac")) {
|
||||
std::cerr << "ERROR: Filetype is not supported, supported types are .mp3, .flac" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show( );
|
||||
MainWindow* w = argc > 1 && CheckValidFile(std::filesystem::path(argv[1])) ? new MainWindow(std::filesystem::path(argv[1])) : new MainWindow( );
|
||||
w->setMinimumHeight(600);
|
||||
w->show( );
|
||||
|
||||
return a.exec( );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user