***************
*** 1082,1190 ****
  
      if (!tagcache_search(&tcs, tag))
          return -1;
-     
      /* Prevent duplicate entries in the search list. */
      tagcache_search_set_uniqbuf(&tcs, uniqbuf, UNIQBUF_SIZE);
-     
      if (level || csi->clause_count[0] || TAGCACHE_IS_NUMERIC(tag))
          sort = true;
-     
      for (i = 0; i < level; i++)
      {
          if (TAGCACHE_IS_NUMERIC(csi->tagorder[i]))
          {
              static struct tagcache_search_clause cc;
-             
              memset(&cc, 0, sizeof(struct tagcache_search_clause));
              cc.tag = csi->tagorder[i];
              cc.type = clause_is;
              cc.numeric = true;
              cc.numeric_data = csi->result_seek[i];
-             tagcache_search_add_clause(&tcs, &cc);
          }
          else
          {
-             tagcache_search_add_filter(&tcs, csi->tagorder[i], 
                                         csi->result_seek[i]);
          }
      }
-    
      for (i = 0; i <= level; i++)
      {
-         int j;
-         
          for (j = 0; j < csi->clause_count[i]; j++)
-             tagcache_search_add_clause(&tcs, csi->clause[i][j]);
      }
-     
      current_offset = offset;
      current_entry_count = 0;
      c->dirfull = false;
-     
-     fmt = NULL;
-     for (i = 0; i < format_count; i++)
      {
-         if (formats[i]->group_id == csi->format_id[level])
-             fmt = formats[i];
      }
  
      if (fmt)
      {
          sort_inverse = fmt->sort_inverse;
          sort_limit = fmt->limit;
-         strip = fmt->strip;
          sort = true;
      }
      else
      {
          sort_inverse = false;
          sort_limit = 0;
-         strip = 0;
      }
-     
-     if (tag != tag_title && tag != tag_filename)
      {
          if (offset == 0)
          {
              dptr->newtable = ALLSUBENTRIES;
              dptr->name = str(LANG_TAGNAVI_ALL_TRACKS);
              dptr++;
              current_entry_count++;
          }
          if (offset <= 1)
          {
              dptr->newtable = NAVIBROWSE;
              dptr->name = str(LANG_TAGNAVI_RANDOM);
              dptr->extraseek = -1;
              dptr++;
              current_entry_count++;
          }
-         special_entry_count+=2;
      }
-     
      total_count += special_entry_count;
-     
      while (tagcache_get_next(&tcs))
      {
          if (total_count++ < offset)
              continue;
-         
-         dptr->newtable = NAVIBROWSE;
-         if (tag == tag_title || tag == tag_filename)
          {
              dptr->newtable = PLAYTRACK;
              dptr->extraseek = tcs.idx_id;
          }
          else
              dptr->extraseek = tcs.result_seek;
-         
          fmt = NULL;
          /* Check the format */
          for (i = 0; i < format_count; i++)
          {
-             if (formats[i]->group_id != csi->format_id[level])
                  continue;
-             
              if (tagcache_check_clauses(&tcs, formats[i]->clause,
                                         formats[i]->clause_count))
              {
--- 1096,1256 ----
  
      if (!tagcache_search(&tcs, tag))
          return -1;
+ 
      /* Prevent duplicate entries in the search list. */
      tagcache_search_set_uniqbuf(&tcs, uniqbuf, UNIQBUF_SIZE);
+ 
      if (level || csi->clause_count[0] || TAGCACHE_IS_NUMERIC(tag))
          sort = true;
+ 
+     /* Add filters for each parent level */
      for (i = 0; i < level; i++)
      {
          if (TAGCACHE_IS_NUMERIC(csi->tagorder[i]))
          {
              static struct tagcache_search_clause cc;
+ 
              memset(&cc, 0, sizeof(struct tagcache_search_clause));
              cc.tag = csi->tagorder[i];
              cc.type = clause_is;
              cc.numeric = true;
              cc.numeric_data = csi->result_seek[i];
+             tagcache_search_add_clause(&tcs, &cc, true);
          }
          else
          {
+             tagcache_search_add_filter(&tcs, csi->tagorder[i],
                                         csi->result_seek[i]);
          }
      }
+ 
+     /* Add clauses for each level in the menu */
      for (i = 0; i <= level; i++)
      {
          for (j = 0; j < csi->clause_count[i]; j++)
+         {
+             tagcache_search_add_clause(&tcs, csi->clause[i][j], true);
+ 		}
      }
+ 
      current_offset = offset;
      current_entry_count = 0;
      c->dirfull = false;
+ 
+ 	if (alltracks)
+ 	{
+         /* All Tracks format functionality */
+         sort = true;
+         all_tracks_fmt[0] = '\0';
+ 
+         /* Construct the All format name by concatenating the menu level tags */
+         for (i = 0; i <= level; i++)
+         {
+             strcat(all_tracks_fmt, tags_str[csi->tagorder[i]]);
+             strcat(all_tracks_fmt, ".");
+         }
+         strcat(all_tracks_fmt, "All");
+ 
+         /* look for any AllTracks format matching the derived format name */
+         fmt = NULL;
+         for (i = 0; i < format_count; i++)
+         {
+             if (!strcasecmp(formats[i]->name, all_tracks_fmt))
+             {
+                 /* add all possible clauses for all formats */
+                 fmt = formats[i];
+                 for (j = 0; j < fmt->clause_count; j++)
+                 {
+                     tagcache_search_add_clause(&tcs, fmt->clause[j], false);
+                 }
+             }
+         }
+     }
+     else
      {
+         fmt = NULL;
+         for (i = 0; i < format_count; i++)
+         {
+             if (formats[i]->group_id == csi->format_id[level])
+             {
+                 /* Ensure that tags from all clauses for the fmt are loaded */
+                 fmt = formats[i];
+                 for (j = 0; j < fmt->clause_count; j++)
+                 {
+                     tagcache_search_add_clause(&tcs, fmt->clause[j], false);
+                 }
+             }
+         }
      }
  
+     /* The assigning of the sort_inverse and sort_limit fields here is a bit arbitrary since any
+        track title can match any one of the associated formats, each of which can have a different
+        set of values for the sort inverse and sort limit attributes. */
      if (fmt)
      {
          sort_inverse = fmt->sort_inverse;
          sort_limit = fmt->limit;
          sort = true;
      }
      else
      {
+ 		/* No global format */
          sort_inverse = false;
          sort_limit = 0;
      }
+ 
+     if ((tag != tag_title) && (tag != tag_filename))
      {
          if (offset == 0)
          {
+ 			/* Adds the <All Tracks> option */
              dptr->newtable = ALLSUBENTRIES;
              dptr->name = str(LANG_TAGNAVI_ALL_TRACKS);
              dptr++;
              current_entry_count++;
+             special_entry_count++;
          }
          if (offset <= 1)
          {
+ 			/* Adds the <Random> option */
              dptr->newtable = NAVIBROWSE;
              dptr->name = str(LANG_TAGNAVI_RANDOM);
              dptr->extraseek = -1;
              dptr++;
              current_entry_count++;
+             special_entry_count++;
          }
      }
+ 
      total_count += special_entry_count;
+ 
+ 	/* Now cycle through each entry and apply any formatting */
      while (tagcache_get_next(&tcs))
      {
          if (total_count++ < offset)
              continue;
+ 
+         dptr->strip = 0; 	/* set the default strip amount for this entry */
+         if ((tag == tag_title) || (tag == tag_filename))
          {
              dptr->newtable = PLAYTRACK;
              dptr->extraseek = tcs.idx_id;
          }
          else
+         {
+ 			dptr->newtable = NAVIBROWSE;
              dptr->extraseek = tcs.result_seek;
+ 		}
+ 
          fmt = NULL;
          /* Check the format */
          for (i = 0; i < format_count; i++)
          {
+             /* Handle the allsubentries case as well - look for format defined in all_tracks_fmt */
+             if (((formats[i]->group_id != csi->format_id[level]) && !alltracks) ||
+                     (alltracks && strcasecmp(formats[i]->name, all_tracks_fmt)))
                  continue;
+ 
              if (tagcache_check_clauses(&tcs, formats[i]->clause,
                                         formats[i]->clause_count))
              {
