Discussion:
[PATCH 1/3] fix cache refresh bug [2]
Johannes Weißl
2011-05-10 03:00:57 UTC
Permalink
see 7c04a6b22e9306627f92c729f9d0dcbb4365d9f9
---
cache.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cache.c b/cache.c
index 9b5c85d..53ab2a0 100644
--- a/cache.c
+++ b/cache.c
@@ -493,6 +493,6 @@ struct track_info **cache_refresh(int *count, int force)
ti->next = NULL;
}
}
- *count = total;
+ *count = n;
return tis;
}
--
1.7.5.1
Johannes Weißl
2011-05-10 03:00:59 UTC
Permalink
---
job.c | 7 +++++++
player.c | 20 +++++++++++++++-----
player.h | 3 +++
3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/job.c b/job.c
index d9127a2..0a44447 100644
--- a/job.c
+++ b/job.c
@@ -30,6 +30,7 @@
#include "utils.h"
#include "file.h"
#include "cache.h"
+#include "player.h"

#include <string.h>
#include <unistd.h>
@@ -289,6 +290,7 @@ void do_update_cache_job(void *data)
cache_lock();
tis = cache_refresh(&count, d->force);
editable_lock();
+ player_info_lock();
for (i = 0; i < count; i++) {
struct track_info *new, *old = tis[i];

@@ -300,11 +302,16 @@ void do_update_cache_job(void *data)
lib_add_track(new);
editable_update_track(&pl_editable, old, new);
play_queue_update_track(old, new);
+ if (player_info.ti == old && new) {
+ track_info_ref(new);
+ player_file_changed(new);
+ }

track_info_unref(old);
if (new)
track_info_unref(new);
}
+ player_info_unlock();
editable_unlock();
cache_unlock();
free(tis);
diff --git a/player.c b/player.c
index 58518c1..674641f 100644
--- a/player.c
+++ b/player.c
@@ -393,21 +393,26 @@ static inline int get_next(struct track_info **ti)

/* updating player status {{{ */

-static inline void file_changed(struct track_info *ti)
+static inline void __file_changed(struct track_info *ti)
{
- player_info_lock();
if (player_info.ti)
track_info_unref(player_info.ti);

player_info.ti = ti;
+ update_rg_scale();
+ player_info.metadata[0] = 0;
+ player_info.file_changed = 1;
+}
+
+static inline void file_changed(struct track_info *ti)
+{
+ player_info_lock();
if (ti) {
d_print("file: %s\n", ti->filename);
} else {
d_print("unloaded\n");
}
- update_rg_scale();
- player_info.metadata[0] = 0;
- player_info.file_changed = 1;
+ __file_changed(ti);
player_info_unlock();
}

@@ -1175,6 +1180,11 @@ out:
player_unlock();
}

+void player_file_changed(struct track_info *ti)
+{
+ __file_changed(ti);
+}
+
void player_seek(double offset, int relative, int start_playing)
{
int stopped = 0;
diff --git a/player.h b/player.h
index 5e9efe1..6bae225 100644
--- a/player.h
+++ b/player.h
@@ -98,6 +98,9 @@ void player_set_file(struct track_info *ti);
/* set current file and start playing */
void player_play_file(struct track_info *ti);

+/* update track info */
+void player_file_changed(struct track_info *ti);
+
void player_play(void);
void player_stop(void);
void player_pause(void);
--
1.7.5.1
Johannes Weißl
2011-05-10 03:00:58 UTC
Permalink
---
editable.c | 22 ++++++++++++++++++++++
editable.h | 1 +
job.c | 4 +++-
play_queue.c | 31 ++++++++++++++++++++++++++++---
play_queue.h | 1 +
5 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/editable.c b/editable.c
index 4882b7c..1d2a1d0 100644
--- a/editable.c
+++ b/editable.c
@@ -370,3 +370,25 @@ int editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track
window_down(e->win, 1);
return rc;
}
+
+void editable_update_track(struct editable *e, struct track_info *old, struct track_info *new)
+{
+ struct list_head *item, *tmp;
+ int changed = 0;
+
+ list_for_each_safe(item, tmp, &e->head) {
+ struct simple_track *track = to_simple_track(item);
+ if (track->info == old) {
+ if (new) {
+ track_info_unref(old);
+ track_info_ref(new);
+ track->info = new;
+ } else {
+ editable_remove_track(e, track);
+ }
+ changed = 1;
+ }
+ }
+ if (changed)
+ e->win->changed = changed;
+}
diff --git a/editable.h b/editable.h
index 5880a6c..a42451e 100644
--- a/editable.h
+++ b/editable.h
@@ -60,6 +60,7 @@ int __editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct tra
void *data, int reverse);
int editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
void *data, int reverse);
+void editable_update_track(struct editable *e, struct track_info *old, struct track_info *new);

static inline void editable_track_to_iter(struct editable *e, struct simple_track *track, struct iter *iter)
{
diff --git a/job.c b/job.c
index 6df02ee..d9127a2 100644
--- a/job.c
+++ b/job.c
@@ -24,6 +24,7 @@
#include "load_dir.h"
#include "path.h"
#include "editable.h"
+#include "pl.h"
#include "play_queue.h"
#include "lib.h"
#include "utils.h"
@@ -297,7 +298,8 @@ void do_update_cache_job(void *data)
new = old->next;
if (lib_remove(old) && new)
lib_add_track(new);
- // FIXME: other views
+ editable_update_track(&pl_editable, old, new);
+ play_queue_update_track(old, new);

track_info_unref(old);
if (new)
diff --git a/play_queue.c b/play_queue.c
index 70c4196..6b1b966 100644
--- a/play_queue.c
+++ b/play_queue.c
@@ -58,14 +58,12 @@ void play_queue_prepend(struct track_info *ti)
window_changed(pq_editable.win);
}

-struct track_info *play_queue_remove(void)
+static struct track_info *pq_remove_track(struct list_head *item)
{
- struct list_head *item;
struct simple_track *t;
struct track_info *info;
struct iter iter;

- item = pq_editable.head.next;
if (item == &pq_editable.head)
return NULL;

@@ -83,6 +81,11 @@ struct track_info *play_queue_remove(void)
return info;
}

+struct track_info *play_queue_remove(void)
+{
+ return pq_remove_track(pq_editable.head.next);
+}
+
int play_queue_for_each(int (*cb)(void *data, struct track_info *ti), void *data)
{
struct simple_track *track;
@@ -95,3 +98,25 @@ int play_queue_for_each(int (*cb)(void *data, struct track_info *ti), void *data
}
return rc;
}
+
+void play_queue_update_track(struct track_info *old, struct track_info *new)
+{
+ struct list_head *item, *tmp;
+ int changed = 0;
+
+ list_for_each_safe(item, tmp, &pq_editable.head) {
+ struct simple_track *track = to_simple_track(item);
+ if (track->info == old) {
+ if (new) {
+ track_info_unref(old);
+ track_info_ref(new);
+ track->info = new;
+ } else {
+ pq_remove_track(item);
+ }
+ changed = 1;
+ }
+ }
+ if (changed)
+ window_changed(pq_editable.win);
+}
diff --git a/play_queue.h b/play_queue.h
index 201ec79..942eba4 100644
--- a/play_queue.h
+++ b/play_queue.h
@@ -29,5 +29,6 @@ void play_queue_append(struct track_info *ti);
void play_queue_prepend(struct track_info *ti);
struct track_info *play_queue_remove(void);
int play_queue_for_each(int (*cb)(void *data, struct track_info *ti), void *data);
+void play_queue_update_track(struct track_info *old, struct track_info *new);

#endif
--
1.7.5.1
Gregory Petrosyan
2011-05-10 08:52:30 UTC
Permalink
Post by Johannes Weißl
see 7c04a6b22e9306627f92c729f9d0dcbb4365d9f9
Merged all 3, thanks!

Gregory

Loading...