From c727aaa526293594878712c1435ec496465d0515 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 29 Oct 2011 15:19:56 -0400 Subject: [PATCH] ocarina: Fill a songlist by inheriting from a SourceModel The SourceModel declares an insert() function that is called when filling the list. I have defined this function in a way that the list will be filled in through repeated calls to insert() --- include/ocarina/songlist.h | 6 +++--- ocarina/library.cpp | 7 ------- ocarina/songlist/fill.cpp | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/include/ocarina/songlist.h b/include/ocarina/songlist.h index fa2d5d5c..48ac113d 100644 --- a/include/ocarina/songlist.h +++ b/include/ocarina/songlist.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,12 +12,11 @@ using namespace std; /* Make this a class to inherit from? */ struct SongListFuncs { - void (*for_each)(void (*)(Track &)); - void (*insert_track)(Track &); + void (*for_each)(libsaria::SourceModel *); unsigned int (*size)(); }; -class SongList +class SongList : public libsaria::SourceModel { private: int ins_next; diff --git a/ocarina/library.cpp b/ocarina/library.cpp index d4c234ea..341b6f9e 100644 --- a/ocarina/library.cpp +++ b/ocarina/library.cpp @@ -13,14 +13,12 @@ using namespace std; static SongList library_list; void ocarina_library_refresh(); -static void library_insert(Track &); struct SongListFuncs library_funcs; void library_init() { library_funcs.for_each = libsaria::library::for_each; - library_funcs.insert_track = library_insert; library_funcs.size = libsaria::library::size; library_list.init("Library", &library_funcs); @@ -28,11 +26,6 @@ void library_init() ocarina_library_refresh(); } -static void library_insert(Track &track) -{ - library_list.insert(track); -} - void ocarina_library_refresh() { library_list.clear(); diff --git a/ocarina/songlist/fill.cpp b/ocarina/songlist/fill.cpp index 35a01803..b9ad83f3 100644 --- a/ocarina/songlist/fill.cpp +++ b/ocarina/songlist/fill.cpp @@ -38,7 +38,7 @@ void SongList::fill() { freeze(); ins_next = 0; - list_funcs->for_each(list_funcs->insert_track); + list_funcs->for_each(this); thaw(); set_label_text(); }