Skip to content

Commit

Permalink
[MED] ALPHA 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nots1dd committed Jan 12, 2025
1 parent 0f54333 commit cbbe765
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 102 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,34 @@ Weird commit that sets up for better and more transparent way of understanding t
- Runtime errors with respect to `PlayCurrentSong()` that may be due to detaching the audio thread

---

## [ALPHA 1.7] --- 13-01-2025

### Added
- `src/ui/thread_manager.hpp` -> To handle concurrency in UI with testing + doxygen docs setup

- A LOT of new color fields to `config.toml` (Check it out) with subsequent integration in `src/ui/colors.hpp` and `src/ui/ui_handler.hpp`

- Some object deletion and freeing when calling MPRISService destructor

- `src/signal` -> To catch all signals and handle gracefully (**FULL INTEGRATION NOT DONE YET**)

- Some changes to format lyrics function and added ComponentState in `src/ui/misc.hpp` to keep track of all components of UI together

### Changed
- Added more functions in misc.hpp to refactor code in ui_handler

### Fixed
- Finally fixed scrolling lyrics menu issue, now it completely works with testing

- Weird issue with deletion of song from queue is fully fixed with testing

### Removed
**NIL**

Sizeable commit with refactoring and more configuration options as its priority, more such commits expected in future

### Known Issues to fix in immediate commits
- Runtime errors with respect to `PlayCurrentSong()` that may be due to detaching the audio thread

---
29 changes: 16 additions & 13 deletions src/dbus/mpris-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,22 @@ class MPRISService

~MPRISService()
{
if (connection_)
{
g_object_unref(connection_);
}
if (introspection_data_)
{
g_dbus_node_info_unref(introspection_data_);
}
if (current_metadata_)
{
g_variant_unref(current_metadata_);
}
std::cout << "-- MPRISService cleaned up." << std::endl;
if (connection_)
{
g_object_unref(connection_);
connection_ = nullptr;
}
if (introspection_data_)
{
g_dbus_node_info_unref(introspection_data_);
introspection_data_ = nullptr;
}
if (current_metadata_)
{
g_variant_unref(current_metadata_);
current_metadata_ = nullptr;
}
std::cout << "-- MPRISService cleaned up." << std::endl;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "dirsort/inode_mapper.hpp"
#include "ui/ui_handler.hpp"
#include "signal/signalHandler.hpp"
#include <memory>
#include <random>

int main(int argc, char* argv[])
{
SignalHandler::getInstance().setup();
string directoryPath = string(parseTOMLField(PARENT_LIB, PARENT_LIB_FIELD_DIR));
string libSyncPath = getConfigPath(LIB_SYNC_NAME);
RedBlackTree rbt;
Expand Down
41 changes: 33 additions & 8 deletions src/parser/examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,36 @@ view_song_queue = "3"

# Colors format: Solid Colors and Hexadecimal values of format `#RRGGBB`
[colors]
active_win_color = "Blue"
inactive_win_color = "#282828"
album_name_bg = "LightPink"
menu_cursor_bg = "LightYellow"
artists_title_bg = "#458586"
artists_title_fg = "#E9DDB5"
songs_title_bg = "#D7981E"
songs_title_fg = "#E9DDB5"
# Window Border Colors
active_win_border_color = "#D65D0E" # Orange for active borders
inactive_win_border_color = "#3C3836" # Dark grey for inactive borders

# Album Section
album_name_bg = "#83A598" # Muted cyan for background

# Menu Cursor
menu_cursor_bg = "#8EC07C" # Soft green for cursor background

# Artists Title Section
artists_title_bg = "#458588" # Deep teal for background
artists_title_fg = "#EBDBB2" # Gruvbox light for foreground

# Songs Title Section
songs_title_bg = "#D79921" # Warm yellow for background
songs_title_fg = "#EBDBB2" # Gruvbox light for foreground

# Song Queue Menu
song_queue_menu_bor_col = "#B16286" # Muted magenta for border
song_queue_menu_fg = "#D3869B" # Soft pink for foreground

# Progress Bar
progress_bar_playing_col = "#83A598" # Cyan for playing state
progress_bar_not_playing_col = "#FABD2F" # Bright yellow for not playing state

# Volume Bar
volume_bar_col = "#8EC07C" # Soft green for volume bar

# Status Bar
status_bar_bg = "#504945" # Dark gray for background
status_bar_artist_col = "#FB4934" # Bright red for artist name
status_bar_song_col = "#FABD2F" # Bright yellow for song name
68 changes: 68 additions & 0 deletions src/signal/signalHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef SIGNAL_HANDLER_HPP
#define SIGNAL_HANDLER_HPP

#include <iostream>
#include <csignal>
#include <execinfo.h>
#include <cstdlib>
#include <unistd.h>
#include <string>

class SignalHandler {
public:
// Singleton instance getter
static SignalHandler& getInstance() {
static SignalHandler instance;
return instance;
}

// Initialize the signal handler
void setup() {
struct sigaction sa;
sa.sa_sigaction = SignalHandler::handleSignal; // Use static member function
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO; // Use siginfo_t for extended info

sigaction(SIGABRT, &sa, nullptr); // Catch SIGABRT
sigaction(SIGSEGV, &sa, nullptr); // Catch SIGSEGV
}

private:
SignalHandler() = default; // Private constructor for singleton
~SignalHandler() = default;

// Non-copyable and non-movable
SignalHandler(const SignalHandler&) = delete;
SignalHandler& operator=(const SignalHandler&) = delete;

// Signal handling function
static void handleSignal(int signal, siginfo_t* info, void* context) {
const char* signalName = nullptr;
switch (signal) {
case SIGABRT: signalName = "SIGABRT"; break;
case SIGSEGV: signalName = "SIGSEGV"; break;
default: signalName = "Unknown"; break;
}

std::cerr << "\n=== Signal Caught ===\n";
std::cerr << "Signal: " << signalName << " (" << signal << ")\n";
if (info) {
std::cerr << "Address causing signal: " << info->si_addr << "\n";
}

// Generate a backtrace
void* buffer[128];
int size = backtrace(buffer, 128);
std::cerr << "Backtrace (" << size << " frames):\n";
char** symbols = backtrace_symbols(buffer, size);
for (int i = 0; i < size; ++i) {
std::cerr << symbols[i] << '\n';
}
free(symbols);

// Clean termination
_Exit(EXIT_FAILURE);
}
};

#endif
28 changes: 23 additions & 5 deletions src/ui/colors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,22 @@ ftxui::Color GetColor(Color color)

struct InLimboColors
{
ftxui::Color active_win_color;
ftxui::Color inactive_win_color;
ftxui::Color active_win_border_color;
ftxui::Color inactive_win_border_color;
ftxui::Color album_name_bg;
ftxui::Color menu_cursor_bg;
ftxui::Color artists_title_bg;
ftxui::Color artists_title_fg;
ftxui::Color songs_title_bg;
ftxui::Color songs_title_fg;
ftxui::Color song_queue_menu_bor_col;
ftxui::Color song_queue_menu_fg;
ftxui::Color progress_bar_playing_col;
ftxui::Color progress_bar_not_playing_col;
ftxui::Color volume_bar_col;
ftxui::Color status_bar_bg;
ftxui::Color status_bar_artist_col;
ftxui::Color status_bar_song_col;
};

/**
Expand Down Expand Up @@ -302,14 +310,24 @@ InLimboColors parseColors()

// Mapping of fields in the InLimboColors struct
const std::unordered_map<std::string, ftxui::Color*> field_map = {
{"active_win_color", &colors.active_win_color},
{"inactive_win_color", &colors.inactive_win_color},
{"active_win_border_color", &colors.active_win_border_color},
{"inactive_win_border_color", &colors.inactive_win_border_color},
{"album_name_bg", &colors.album_name_bg},
{"menu_cursor_bg", &colors.menu_cursor_bg},
{"artists_title_bg", &colors.artists_title_bg},
{"artists_title_fg", &colors.artists_title_fg},
{"songs_title_bg", &colors.songs_title_bg},
{"songs_title_fg", &colors.songs_title_fg}};
{"songs_title_fg", &colors.songs_title_fg},
{"song_queue_menu_bor_col", &colors.song_queue_menu_bor_col},
{"song_queue_menu_fg", &colors.song_queue_menu_fg},
{"progress_bar_playing_col", &colors.progress_bar_playing_col},
{"progress_bar_not_playing_col", &colors.progress_bar_not_playing_col},
{"volume_bar_col", &colors.volume_bar_col},
{"status_bar_bg", &colors.status_bar_bg},
{"status_bar_artist_col", &colors.status_bar_artist_col},
{"status_bar_song_col", &colors.status_bar_song_col},

};

for (const auto& [field, member_color] : field_map)
{
Expand Down
41 changes: 34 additions & 7 deletions src/ui/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,55 @@
#include <string>
#include <vector>

struct ComponentState
{
Component artists_list;
Component songs_list;
Component songs_queue_comp;
Component lyrics_scroller;
Component MainRenderer;
};

std::vector<std::string> formatLyrics(const std::string& lyrics)
{
std::vector<std::string> lines;
std::string currentLine;
bool insideBrackets = false;
bool insideSquareBrackets = false;
bool insideCurlBrackets = false;
bool lastWasUppercase = false;
bool lastWasSpecialChar = false; // Tracks special characters within words
char previousChar = '\0';

for (char c : lyrics)
{
if (c == '[')
if (c == '[' || c == '(')
{
if (!currentLine.empty())
{
lines.push_back(currentLine);
currentLine.clear();
}
insideBrackets = true;
if (c == '[') insideSquareBrackets = true;
else insideCurlBrackets = true;
currentLine += c;
continue;
}

if (insideBrackets)
if (insideSquareBrackets || insideCurlBrackets)
{
currentLine += c;
if (c == ']')
if (c == ']' && insideSquareBrackets)
{
lines.push_back(currentLine);
currentLine.clear();
insideSquareBrackets = false;
}

else if (c == ')' && insideCurlBrackets)
{
lines.push_back(currentLine);
currentLine.clear();
insideBrackets = false;
insideCurlBrackets = false;
}
continue;
}
Expand Down Expand Up @@ -142,6 +160,15 @@ Element renderSongName(const std::string& disc_track_info, const std::string& so
text(FormatTime(duration)) | align_right});
}

Component CreateMenu(const std::vector<std::string>* vecLines, int *currLine)
{
MenuOption menu_options;
menu_options.on_change = [&]() {};
menu_options.focused_entry = currLine;

return Menu(vecLines, currLine, menu_options);
}

// TODO: Make Song Menu dynamically scrollable
auto RenderSongMenu(const std::vector<Element>& items, int* selected_index, ftxui::Color sel_color)
{
Expand All @@ -153,7 +180,7 @@ auto RenderSongMenu(const std::vector<Element>& items, int* selected_index, ftxu
auto style = is_selected ? color(sel_color) : nothing;
auto inverted_style = is_selected ? inverted : nothing;
/*auto playing_style = is_playing ? getTrueColor(playing_color) : nothing;*/
rendered_items.push_back(items[i] | style | inverted_style);
rendered_items.push_back(items[i] | style | inverted_style | frame);
}

return vbox(std::move(rendered_items));
Expand Down
Loading

0 comments on commit cbbe765

Please sign in to comment.