Implement start of Playback Engine, refactored most classes to leverage KotoCartographer, etc.
This commit is contained in:
parent
a77efdb0aa
commit
05d90afc58
25 changed files with 1015 additions and 304 deletions
|
@ -18,9 +18,11 @@
|
|||
#include <glib-2.0/glib.h>
|
||||
#include <sqlite3.h>
|
||||
#include <taglib/tag_c.h>
|
||||
#include "../db/cartographer.h"
|
||||
#include "structs.h"
|
||||
#include "koto-utils.h"
|
||||
|
||||
extern KotoCartographer *koto_maps;
|
||||
extern sqlite3 *koto_db;
|
||||
|
||||
struct _KotoIndexedTrack {
|
||||
|
@ -32,10 +34,9 @@ struct _KotoIndexedTrack {
|
|||
|
||||
gchar *file_name;
|
||||
gchar *parsed_name;
|
||||
gchar *artist;
|
||||
gchar *album;
|
||||
guint *cd;
|
||||
guint *position;
|
||||
guint *playback_position;
|
||||
|
||||
gboolean acquired_metadata_from_id3;
|
||||
gboolean do_initial_index;
|
||||
|
@ -49,13 +50,12 @@ enum {
|
|||
PROP_ALBUM_UUID,
|
||||
PROP_UUID,
|
||||
PROP_DO_INITIAL_INDEX,
|
||||
PROP_ARTIST,
|
||||
PROP_ALBUM,
|
||||
PROP_PATH,
|
||||
PROP_FILE_NAME,
|
||||
PROP_PARSED_NAME,
|
||||
PROP_CD,
|
||||
PROP_POSITION,
|
||||
PROP_PLAYBACK_POSITION,
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
||||
|
@ -110,22 +110,6 @@ static void koto_indexed_track_class_init(KotoIndexedTrackClass *c) {
|
|||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
props[PROP_ARTIST] = g_param_spec_string(
|
||||
"artist",
|
||||
"Name of Artist",
|
||||
"Name of Artist",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
props[PROP_ALBUM] = g_param_spec_string(
|
||||
"album",
|
||||
"Name of Album",
|
||||
"Name of Album",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
props[PROP_FILE_NAME] = g_param_spec_string(
|
||||
"file-name",
|
||||
"Name of File",
|
||||
|
@ -162,6 +146,16 @@ static void koto_indexed_track_class_init(KotoIndexedTrackClass *c) {
|
|||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
props[PROP_PLAYBACK_POSITION] = g_param_spec_uint(
|
||||
"playback-position",
|
||||
"Current playback position",
|
||||
"Current playback position",
|
||||
0,
|
||||
G_MAXUINT16,
|
||||
0,
|
||||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
g_object_class_install_properties(gobject_class, N_PROPERTIES, props);
|
||||
}
|
||||
|
||||
|
@ -182,12 +176,6 @@ static void koto_indexed_track_get_property(GObject *obj, guint prop_id, GValue
|
|||
case PROP_UUID:
|
||||
g_value_set_string(val, self->uuid);
|
||||
break;
|
||||
case PROP_ARTIST:
|
||||
g_value_set_string(val, self->artist);
|
||||
break;
|
||||
case PROP_ALBUM:
|
||||
g_value_set_string(val, self->album);
|
||||
break;
|
||||
case PROP_PATH:
|
||||
g_value_set_string(val, self->path);
|
||||
break;
|
||||
|
@ -203,6 +191,9 @@ static void koto_indexed_track_get_property(GObject *obj, guint prop_id, GValue
|
|||
case PROP_POSITION:
|
||||
g_value_set_uint(val, GPOINTER_TO_UINT(self->position));
|
||||
break;
|
||||
case PROP_PLAYBACK_POSITION:
|
||||
g_value_set_uint(val, GPOINTER_TO_UINT(self->playback_position));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec);
|
||||
break;
|
||||
|
@ -228,12 +219,6 @@ static void koto_indexed_track_set_property(GObject *obj, guint prop_id, const G
|
|||
case PROP_DO_INITIAL_INDEX:
|
||||
self->do_initial_index = g_value_get_boolean(val);
|
||||
break;
|
||||
case PROP_ARTIST:
|
||||
self->artist = g_strdup(g_value_get_string(val));
|
||||
break;
|
||||
case PROP_ALBUM:
|
||||
self->album = g_strdup(g_value_get_string(val));
|
||||
break;
|
||||
case PROP_PATH:
|
||||
koto_indexed_track_update_path(self, g_value_get_string(val)); // Update the path
|
||||
break;
|
||||
|
@ -249,6 +234,9 @@ static void koto_indexed_track_set_property(GObject *obj, guint prop_id, const G
|
|||
case PROP_POSITION:
|
||||
koto_indexed_track_set_position(self, g_value_get_uint(val));
|
||||
break;
|
||||
case PROP_PLAYBACK_POSITION:
|
||||
self->playback_position = GUINT_TO_POINTER(g_value_get_uint(val));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec);
|
||||
break;
|
||||
|
@ -293,14 +281,22 @@ void koto_indexed_track_commit(KotoIndexedTrack *self) {
|
|||
void koto_indexed_track_parse_name(KotoIndexedTrack *self) {
|
||||
gchar *copied_file_name = g_strdelimit(g_strdup(self->file_name), "_", ' '); // Replace _ with whitespace for starters
|
||||
|
||||
if (self->artist != NULL && strcmp(self->artist, "") != 0) { // If we have artist set
|
||||
gchar **split = g_strsplit(copied_file_name, self->artist, -1); // Split whenever we encounter the artist
|
||||
copied_file_name = g_strjoinv("", split); // Remove the artist
|
||||
g_strfreev(split);
|
||||
KotoIndexedArtist *artist = NULL;
|
||||
artist = koto_cartographer_get_artist_by_uuid(koto_maps, self->artist_uuid);
|
||||
|
||||
split = g_strsplit(copied_file_name, g_utf8_strdown(self->artist, -1), -1); // Lowercase album name and split by that
|
||||
copied_file_name = g_strjoinv("", split); // Remove the artist
|
||||
g_strfreev(split);
|
||||
if (artist != NULL) { // If we have artist
|
||||
gchar *artist_name = NULL;
|
||||
g_object_get(artist, "name", &artist_name, NULL);
|
||||
|
||||
if (artist_name != NULL && (strcmp(artist_name, "") != 0)) {
|
||||
gchar **split = g_strsplit(copied_file_name, artist_name, -1); // Split whenever we encounter the artist
|
||||
copied_file_name = g_strjoinv("", split); // Remove the artist
|
||||
g_strfreev(split);
|
||||
|
||||
split = g_strsplit(copied_file_name, g_utf8_strdown(artist_name, -1), -1); // Lowercase album name and split by that
|
||||
copied_file_name = g_strjoinv("", split); // Remove the artist
|
||||
g_strfreev(split);
|
||||
}
|
||||
}
|
||||
|
||||
gchar *file_without_ext = koto_utils_get_filename_without_extension(copied_file_name);
|
||||
|
@ -339,6 +335,28 @@ void koto_indexed_track_parse_name(KotoIndexedTrack *self) {
|
|||
g_free(file_without_ext);
|
||||
}
|
||||
|
||||
void koto_indexed_track_save_to_playlist(KotoIndexedTrack *self, gchar *playlist_uuid, guint position, gint current) {
|
||||
gchar *commit_op = g_strdup_printf(
|
||||
"INSERT INTO playlist_tracks(playlist_id, track_id, position, current)"
|
||||
"VALUES('%s', '%s', quote(\"%d\"), quote(\"%d\")"
|
||||
"ON CONFLICT(playlist_id, track_id) DO UPDATE SET position=excluded.position, current=excluded.current;",
|
||||
playlist_uuid,
|
||||
self->uuid,
|
||||
position,
|
||||
current
|
||||
);
|
||||
|
||||
gchar *commit_op_errmsg = NULL;
|
||||
int rc = sqlite3_exec(koto_db, commit_op, 0, 0, &commit_op_errmsg);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
g_warning("Failed to save track to playlist: %s", commit_op_errmsg);
|
||||
}
|
||||
|
||||
g_free(commit_op);
|
||||
g_free(commit_op_errmsg);
|
||||
}
|
||||
|
||||
void koto_indexed_track_set_file_name(KotoIndexedTrack *self, gchar *new_file_name) {
|
||||
if (new_file_name == NULL) {
|
||||
return;
|
||||
|
@ -402,9 +420,8 @@ void koto_indexed_track_update_metadata(KotoIndexedTrack *self) {
|
|||
self->acquired_metadata_from_id3 = TRUE;
|
||||
TagLib_Tag *tag = taglib_file_tag(t_file); // Get our tag
|
||||
koto_indexed_track_set_parsed_name(self, taglib_tag_title(tag)); // Set the title of the file
|
||||
self->artist = g_strdup(taglib_tag_artist((tag))); // Set the artist
|
||||
self->album = g_strdup(taglib_tag_album(tag)); // Set the album
|
||||
koto_indexed_track_set_position(self, (uint) taglib_tag_track(tag)); // Get the track, convert to uint and cast as a pointer
|
||||
koto_indexed_track_set_file_name(self, g_path_get_basename(self->path)); // Update our file name
|
||||
} else {
|
||||
koto_indexed_track_set_file_name(self, g_path_get_basename(self->path)); // Update our file name
|
||||
}
|
||||
|
@ -432,29 +449,14 @@ void koto_indexed_track_update_path(KotoIndexedTrack *self, const gchar *new_pat
|
|||
}
|
||||
|
||||
KotoIndexedTrack* koto_indexed_track_new(KotoIndexedAlbum *album, const gchar *path, guint *cd) {
|
||||
KotoIndexedArtist *artist;
|
||||
|
||||
gchar *artist_uuid;
|
||||
gchar *artist_name;
|
||||
gchar *album_uuid;
|
||||
gchar *album_name;
|
||||
|
||||
g_object_get(album, "artist", &artist, NULL); // Get the artist from our Album
|
||||
g_object_get(artist,
|
||||
"name", &artist_name,
|
||||
"uuid", &artist_uuid, // Get the artist UUID from the artist
|
||||
NULL);
|
||||
|
||||
g_object_get(album,
|
||||
"name", &album_name,
|
||||
"uuid", &album_uuid, // Get the album UUID from the album
|
||||
NULL);
|
||||
g_object_get(album, "artist-uuid", &artist_uuid, "uuid", &album_uuid, NULL); // Get the artist and album uuids from our Album
|
||||
|
||||
KotoIndexedTrack *track = g_object_new(KOTO_TYPE_INDEXED_TRACK,
|
||||
"artist-uuid", artist_uuid,
|
||||
"album-uuid", album_uuid,
|
||||
"artist", artist_name,
|
||||
"album", album_name,
|
||||
"do-initial-index", TRUE,
|
||||
"uuid", g_uuid_string_random(),
|
||||
"path", path,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue