inLimbo
TUI Music Player that keeps you in Limbo.
 
Loading...
Searching...
No Matches
state.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <ftxui/component/component.hpp>
6#include <mutex>
7#include <string>
8#include <unordered_map>
9
10using namespace ftxui;
11
12using namespace std;
13
22{
23 Component artists_list;
24 Component songs_list;
25 Component songs_queue_comp;
26 Component lyrics_scroller;
27 Component MainRenderer;
29 Component audioDeviceMenu;
30};
31
40{
41 std::string artist;
42 std::string title;
43 std::string genre;
44 std::string album;
48 int bitrate;
49 unsigned int year;
50 unsigned int track;
51 unsigned int discNumber;
52 std::string lyrics;
53 std::string comment;
54 std::unordered_map<std::string, std::string>
56 std::string filePath;
57
66 void copyMetadata(const Metadata& metadata)
67 {
68 artist = metadata.artist;
69 title = metadata.title;
70 album = metadata.album;
71 genre = metadata.genre;
72 comment = metadata.comment;
73 year = metadata.year;
74 track = metadata.track;
75 discNumber = metadata.discNumber;
76 lyrics = metadata.lyrics;
77 has_comment = (metadata.comment != "No Comment");
78 has_lyrics = (metadata.lyrics != "No Lyrics");
79 filePath = metadata.filePath;
80 bitrate = metadata.bitrate;
82
83 return;
84 }
85
92 auto HasLyrics() -> bool { return has_lyrics; }
100 auto HasComments() -> bool { return has_comment; }
110 auto formatLyrics() -> vector<string>
111 {
112 vector<string> lines;
113 std::string currentLine;
114 bool insideSquareBrackets = false;
115 bool insideCurlBrackets = false;
116 bool lastWasUppercase = false;
117 bool lastWasSpecialChar = false; // Tracks special characters within words
118 char previousChar = '\0';
119
120 for (char c : lyrics)
121 {
122 if (c == '[' || c == '(')
123 {
124 if (!currentLine.empty())
125 {
126 lines.push_back(currentLine);
127 currentLine.clear();
128 }
129 if (c == '[')
130 insideSquareBrackets = true;
131 else
132 insideCurlBrackets = true;
133 currentLine += c;
134 continue;
135 }
136
137 if (insideSquareBrackets || insideCurlBrackets)
138 {
139 currentLine += c;
140 if (c == ']' && insideSquareBrackets)
141 {
142 lines.push_back(currentLine);
143 currentLine.clear();
144 insideSquareBrackets = false;
145 }
146
147 else if (c == ')' && insideCurlBrackets)
148 {
149 lines.push_back(currentLine);
150 currentLine.clear();
151 insideCurlBrackets = false;
152 }
153 continue;
154 }
155
156 if (c == '\'' || c == '-')
157 {
158 currentLine += c;
159 lastWasSpecialChar = true;
160 continue;
161 }
162
163 if (std::isupper(c) && !lastWasUppercase && !lastWasSpecialChar && !currentLine.empty() &&
164 previousChar != '\n' && previousChar != ' ')
165 {
166 lines.push_back(currentLine);
167 currentLine.clear();
168 }
169
170 currentLine += c;
171
172 if (c == '\n')
173 {
174 if (!currentLine.empty())
175 {
176 lines.push_back(currentLine);
177 currentLine.clear();
178 }
179 }
180
181 lastWasUppercase = std::isupper(c);
182 lastWasSpecialChar = false;
183 previousChar = c;
184 }
185
186 if (!currentLine.empty())
187 {
188 lines.push_back(currentLine);
189 }
190
191 // Trim empty lines (optional)
192 lines.erase(std::remove_if(lines.begin(), lines.end(),
193 [](const std::string& line) { return line.empty(); }),
194 lines.end());
195
196 // assign formmated lyrics to member
197 return lines;
198 }
199};
200
218
225
227{
228 vector<Song> song_queue;
229 vector<string> song_queue_names;
230 int qIndex = 0;
231 int qScreenIndex = 0;
232
239 {
240 song_queue.clear();
241 qIndex = 0;
242 }
243
262 void insertSongToIndex(const Song& newSong)
263 {
264 song_queue.insert(song_queue.begin() + qIndex + 1, newSong);
265 }
266
273 void qPush(const Song& song) { song_queue.push_back(song); }
279 void qPopIndex() { song_queue.erase(song_queue.begin() + qScreenIndex); }
287 auto getQueueSize() -> int { return song_queue.size(); }
296 {
297 if (!song_queue.empty() && qIndex < song_queue.size())
298 {
299 return &song_queue[qIndex];
300 }
301
302 return nullptr;
303 }
304
311 {
312 song_queue_names.clear();
313
314 for (long unsigned int i = qIndex; i < song_queue.size(); i++)
315 {
316 std::string eleName = song_queue[i].metadata.title + " by " + song_queue[i].metadata.artist;
317 if (i == qIndex)
318 eleName += " *";
319 song_queue_names.push_back(eleName);
320 }
321
322 return;
323 }
324};
Implements the Trie (Prefix Tree) data structure.
Definition trie.hpp:47
Definition image_view.cpp:17
Holds the components used for rendering the UI.
Definition state.hpp:22
Component songs_queue_comp
Definition state.hpp:25
Component audioDeviceMenu
Definition state.hpp:29
Component lyrics_scroller
Definition state.hpp:26
Component artists_list
Definition state.hpp:23
Component MainRenderer
Definition state.hpp:27
Component songs_list
Definition state.hpp:24
Component ThumbnailRenderer
Definition state.hpp:28
A structure to hold metadata information for a song.
Definition taglib_parser.h:39
unsigned int year
Definition taglib_parser.h:46
std::string filePath
Definition taglib_parser.h:51
unsigned int track
Definition taglib_parser.h:47
std::string title
Definition taglib_parser.h:40
std::string comment
Definition taglib_parser.h:44
std::string lyrics
Definition taglib_parser.h:49
unsigned int discNumber
Definition taglib_parser.h:48
std::string artist
Definition taglib_parser.h:41
int bitrate
Definition taglib_parser.h:53
std::unordered_map< std::string, std::string > additionalProperties
Definition taglib_parser.h:50
std::string album
Definition taglib_parser.h:42
std::string genre
Definition taglib_parser.h:43
Represents the current state of the song being played.
Definition state.hpp:40
std::string filePath
Definition state.hpp:56
unsigned int year
Definition state.hpp:49
unsigned int track
Definition state.hpp:50
int bitrate
Definition state.hpp:48
unsigned int discNumber
Definition state.hpp:51
auto HasComments() -> bool
Checks if the song has comments.
Definition state.hpp:100
std::unordered_map< std::string, std::string > additionalProperties
Definition state.hpp:55
std::string genre
Definition state.hpp:43
bool has_lyrics
Definition state.hpp:46
bool has_comment
Definition state.hpp:45
auto HasLyrics() -> bool
Checks if the song has lyrics.
Definition state.hpp:92
std::string album
Definition state.hpp:44
auto formatLyrics() -> vector< string >
Formats the lyrics into a vector of strings.
Definition state.hpp:110
int duration
Definition state.hpp:47
std::string lyrics
Definition state.hpp:52
std::string title
Definition state.hpp:42
void copyMetadata(const Metadata &metadata)
Copies the metadata from a given Metadata object.
Definition state.hpp:66
std::string artist
Definition state.hpp:41
std::string comment
Definition state.hpp:53
Represents the state of the song queue.
Definition state.hpp:227
void insertSongToIndex(const Song &newSong)
Inserts a song at the current index in the queue.
Definition state.hpp:262
void qPush(const Song &song)
Pushes a song to the end of the queue.
Definition state.hpp:273
vector< string > song_queue_names
Definition state.hpp:229
void incrementQIndex()
Increments the queue index.
Definition state.hpp:248
void UpdateSongQueueList()
Updates the list of song names in the queue.
Definition state.hpp:310
void clearQueue()
Clears the song queue.
Definition state.hpp:238
void qPopIndex()
Pops the song at the current screen index from the queue.
Definition state.hpp:279
vector< Song > song_queue
Definition state.hpp:228
void decrementQIndex()
Decrements the queue index.
Definition state.hpp:254
auto getQueueSize() -> int
Returns the current size of the song queue.
Definition state.hpp:287
int qScreenIndex
Definition state.hpp:231
auto GetCurrentSongFromQueue() -> Song *
Retrieves the current song from the queue.
Definition state.hpp:295
int qIndex
Definition state.hpp:230
Holds the state for searching artists and songs.
Definition state.hpp:209
string input
Definition state.hpp:214
Trie SongSearchTrie
Definition state.hpp:211
int songIndex
Definition state.hpp:213
Trie ArtistSearchTrie
Definition state.hpp:210
int artistIndex
Definition state.hpp:212
int albumsIndex
Definition state.hpp:215
mutex mtx
Definition state.hpp:216
Represents a song with associated metadata and inode.
Definition songmap.hpp:46