@@ -604,6 +604,24 @@ make_cache_dir (char *path, int size)
604604 return sz ;
605605}
606606
607+ static char *
608+ waveform_format_uri (DB_playItem_t * it , const char * uri )
609+ {
610+ if (!it || !uri ) {
611+ return NULL ;
612+ }
613+ int key_len = strlen (uri ) + 10 ;
614+ char * key = malloc (key_len );
615+ if (deadbeef -> pl_get_item_flags (it ) & DDB_IS_SUBTRACK ) {
616+ int subtrack = deadbeef -> pl_find_meta_int (it , ":TRACKNUM" , 0 );
617+ snprintf (key , key_len , "%d%s" , subtrack , uri );
618+ }
619+ else {
620+ snprintf (key , key_len , "%s" , uri );
621+ }
622+ return key ;
623+ }
624+
607625/* copied from ardour3 */
608626static inline float
609627_log_meter (float power , double lower_db , double upper_db , double non_linearity )
@@ -1188,15 +1206,22 @@ waveform_scale (void *user_data, cairo_t *cr, int x, int y, int width, int heigh
11881206}
11891207
11901208void
1191- waveform_db_cache (gpointer user_data , const char * uri )
1209+ waveform_db_cache (gpointer user_data , DB_playItem_t * it , const char * uri )
11921210{
11931211 w_waveform_t * w = user_data ;
1212+ char * key = waveform_format_uri (it , uri );
1213+ if (!key ) {
1214+ return ;
1215+ }
11941216 deadbeef -> mutex_lock (w -> mutex );
11951217 waveform_db_open (cache_path , cache_path_size );
1196- waveform_db_init (uri );
1197- waveform_db_write (uri , w -> buffer , w -> buffer_len * sizeof (short ), w -> channels , 0 );
1218+ waveform_db_init (key );
1219+ waveform_db_write (key , w -> buffer , w -> buffer_len * sizeof (short ), w -> channels , 0 );
11981220 waveform_db_close ();
11991221 deadbeef -> mutex_unlock (w -> mutex );
1222+ if (key ) {
1223+ free (key );
1224+ }
12001225}
12011226
12021227int
@@ -1332,7 +1357,7 @@ waveform_generate_wavedata (gpointer user_data, DB_playItem_t *it, const char *u
13321357 }
13331358 w -> buffer_len = counter ;
13341359 if (CONFIG_CACHE_ENABLED ) {
1335- waveform_db_cache (w , uri );
1360+ waveform_db_cache (w , it , uri );
13361361 }
13371362 deadbeef -> mutex_unlock (w -> mutex );
13381363 if (data ) {
@@ -1353,33 +1378,54 @@ waveform_generate_wavedata (gpointer user_data, DB_playItem_t *it, const char *u
13531378}
13541379
13551380int
1356- waveform_delete (const char * uri )
1381+ waveform_delete (DB_playItem_t * it , const char * uri )
13571382{
1383+ char * key = waveform_format_uri (it , uri );
1384+ if (!key ) {
1385+ return 0 ;
1386+ }
13581387 waveform_db_open (cache_path , cache_path_size );
13591388 waveform_db_init (NULL );
1360- int result = waveform_db_delete (uri );
1389+ int result = waveform_db_delete (key );
13611390 waveform_db_close ();
1391+ if (key ) {
1392+ free (key );
1393+ }
13621394 return result ;
13631395}
13641396
13651397int
1366- waveform_cached (const char * uri )
1398+ waveform_cached (DB_playItem_t * it , const char * uri )
13671399{
1400+ char * key = waveform_format_uri (it , uri );
1401+ if (!key ) {
1402+ return 0 ;
1403+ }
13681404 waveform_db_open (cache_path , cache_path_size );
13691405 waveform_db_init (NULL );
1370- int result = waveform_db_cached (uri );
1406+ int result = waveform_db_cached (key );
13711407 waveform_db_close ();
1408+ if (key ) {
1409+ free (key );
1410+ }
13721411 return result ;
13731412}
13741413
13751414void
1376- waveform_get_from_cache (gpointer user_data , const char * uri )
1415+ waveform_get_from_cache (gpointer user_data , DB_playItem_t * it , const char * uri )
13771416{
13781417 w_waveform_t * w = user_data ;
1418+ char * key = waveform_format_uri (it , uri );
1419+ if (!key ) {
1420+ return ;
1421+ }
13791422 deadbeef -> mutex_lock (w -> mutex );
13801423 waveform_db_open (cache_path , cache_path_size );
1381- w -> buffer_len = waveform_db_read (uri , w -> buffer , w -> max_buffer_len , & w -> channels );
1424+ w -> buffer_len = waveform_db_read (key , w -> buffer , w -> max_buffer_len , & w -> channels );
13821425 waveform_db_close ();
1426+ if (key ) {
1427+ free (key );
1428+ }
13831429 deadbeef -> mutex_unlock (w -> mutex );
13841430}
13851431
@@ -1392,8 +1438,8 @@ waveform_get_wavedata (gpointer user_data)
13921438 if (it ) {
13931439 char * uri = strdup (deadbeef -> pl_find_meta_raw (it , ":URI" ));
13941440 if (uri && waveform_valid_track (it , uri )) {
1395- if (CONFIG_CACHE_ENABLED && waveform_cached (uri )) {
1396- waveform_get_from_cache (w , uri );
1441+ if (CONFIG_CACHE_ENABLED && waveform_cached (it , uri )) {
1442+ waveform_get_from_cache (w , it , uri );
13971443 }
13981444 else {
13991445 waveform_generate_wavedata (w , it , uri );
@@ -1688,8 +1734,8 @@ waveform_action_lookup (DB_plugin_action_t *action, int ctx)
16881734 while (it ) {
16891735 if (deadbeef -> pl_is_selected (it )) {
16901736 const char * uri = deadbeef -> pl_find_meta_raw (it , ":URI" );
1691- if (waveform_cached (uri )) {
1692- waveform_delete (uri );
1737+ if (waveform_cached (it , uri )) {
1738+ waveform_delete (it , uri );
16931739 }
16941740 }
16951741 DB_playItem_t * next = deadbeef -> pl_get_next (it , PL_MAIN );
@@ -1721,7 +1767,7 @@ waveform_get_actions (DB_playItem_t *it)
17211767 lookup_action .flags |= DB_ACTION_DISABLED ;
17221768 DB_playItem_t * current = deadbeef -> pl_get_first (PL_MAIN );
17231769 while (current ) {
1724- if (deadbeef -> pl_is_selected (current ) && waveform_cached (deadbeef -> pl_find_meta_raw (current , ":URI" ))) {
1770+ if (deadbeef -> pl_is_selected (current ) && waveform_cached (current , deadbeef -> pl_find_meta_raw (current , ":URI" ))) {
17251771 lookup_action .flags &= ~DB_ACTION_DISABLED ;
17261772 deadbeef -> pl_item_unref (current );
17271773 break ;
0 commit comments