| 1 | --- Slim.orig/Music/Info.pm 2005-01-10 13:14:59.000000000 +0000 |
|---|
| 2 | +++ Slim/Music/Info.pm 2005-01-17 14:49:37.988443984 +0000 |
|---|
| 3 | @@ -155,6 +155,46 @@ |
|---|
| 4 | ,'mpc' => \&Slim::Formats::Musepack::getTag |
|---|
| 5 | ); |
|---|
| 6 | |
|---|
| 7 | +# Hash containing replacements for lazy multi-tap searching. Anything not in |
|---|
| 8 | +# here will just be translated to itself as we don't have any better idea. See |
|---|
| 9 | +# the lazyMultiTapDecode function for further details of how this works. |
|---|
| 10 | +my %lazyMultiTapMap = ( |
|---|
| 11 | + 'A' => 'A', |
|---|
| 12 | + 'B' => 'AA', |
|---|
| 13 | + 'C' => 'AAA', |
|---|
| 14 | + '2' => 'AAAA', |
|---|
| 15 | + 'D' => 'D', |
|---|
| 16 | + 'E' => 'DD', |
|---|
| 17 | + 'F' => 'DDD', |
|---|
| 18 | + '3' => 'DDDD', |
|---|
| 19 | + 'G' => 'G', |
|---|
| 20 | + 'H' => 'GG', |
|---|
| 21 | + 'I' => 'GGG', |
|---|
| 22 | + '4' => 'GGGG', |
|---|
| 23 | + 'J' => 'J', |
|---|
| 24 | + 'K' => 'JJ', |
|---|
| 25 | + 'L' => 'JJJ', |
|---|
| 26 | + '5' => 'JJJJ', |
|---|
| 27 | + 'M' => 'M', |
|---|
| 28 | + 'N' => 'MM', |
|---|
| 29 | + 'O' => 'MMM', |
|---|
| 30 | + '6' => 'MMMM', |
|---|
| 31 | + 'P' => 'P', |
|---|
| 32 | + 'Q' => 'PP', |
|---|
| 33 | + 'R' => 'PPP', |
|---|
| 34 | + 'S' => 'PPPP', |
|---|
| 35 | + '7' => 'PPPPP', |
|---|
| 36 | + 'T' => 'T', |
|---|
| 37 | + 'U' => 'TT', |
|---|
| 38 | + 'V' => 'TTT', |
|---|
| 39 | + '8' => 'TTTT', |
|---|
| 40 | + 'W' => 'W', |
|---|
| 41 | + 'X' => 'WW', |
|---|
| 42 | + 'Y' => 'WWW', |
|---|
| 43 | + 'Z' => 'WWWW', |
|---|
| 44 | + '9' => 'WWWWW' |
|---|
| 45 | +); |
|---|
| 46 | + |
|---|
| 47 | # if we don't have storable, then stub out the cache routines |
|---|
| 48 | |
|---|
| 49 | if (defined @Storable::EXPORT) { |
|---|
| 50 | @@ -1560,7 +1600,10 @@ |
|---|
| 51 | if ($const eq '') { |
|---|
| 52 | ITEM: foreach my $item (@items) { |
|---|
| 53 | foreach my $regexpattern (@{$patterns}) { |
|---|
| 54 | - if ($item !~ $regexpattern) { |
|---|
| 55 | + my $lazyitem = lazyEncode($item); |
|---|
| 56 | + my $lazyregexpattern = lazyMultiTapDecode($regexpattern); |
|---|
| 57 | + if (($item !~ $regexpattern) && |
|---|
| 58 | + ($lazyitem !~ $lazyregexpattern)) { |
|---|
| 59 | next ITEM; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | @@ -1569,8 +1612,11 @@ |
|---|
| 63 | } else { |
|---|
| 64 | ITEM: foreach my $item (@items) { |
|---|
| 65 | my $item_const = $item . ' ' . $const; |
|---|
| 66 | + my $lazyitem_const = lazyEncode($item_const); |
|---|
| 67 | foreach my $regexpattern (@{$patterns}) { |
|---|
| 68 | - if ($item_const !~ $regexpattern) { |
|---|
| 69 | + my $lazyregexpattern = lazyMultiTapDecode($regexpattern); |
|---|
| 70 | + if (($item_const !~ $regexpattern) && |
|---|
| 71 | + ($lazyitem_const !~ $lazyregexpattern)) { |
|---|
| 72 | next ITEM; |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | @@ -1595,8 +1641,10 @@ |
|---|
| 76 | my @filtereditems; |
|---|
| 77 | my ($k,$v); |
|---|
| 78 | ENTRY: while (($k,$v) = each %{$hashref}) { |
|---|
| 79 | + my $lazyv = lazyEncode($v); |
|---|
| 80 | foreach my $pat (@{$patterns}) { |
|---|
| 81 | - if ($v !~ $pat) { |
|---|
| 82 | + my $lazypat = lazyMultiTapDecode($pat); |
|---|
| 83 | + if (($v !~ $pat) && ($lazyv !~ $lazypat)) { |
|---|
| 84 | next ENTRY; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | @@ -2920,6 +2968,48 @@ |
|---|
| 88 | return $type; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | +# Convert a string to a lazy-entry encoded string. We store this in the |
|---|
| 92 | +# cache so that we can then search for it quickly later. |
|---|
| 93 | +# |
|---|
| 94 | +# called: |
|---|
| 95 | +# undef |
|---|
| 96 | +sub lazyEncode { |
|---|
| 97 | + my $string = shift; |
|---|
| 98 | + # This translates each searchable character into the first character that |
|---|
| 99 | + # appears on that key on the remote. Thus, this gives you what the user |
|---|
| 100 | + # will enter if he doesn't bother to multi-tap to get at the later |
|---|
| 101 | + # characters. |
|---|
| 102 | + # We do all this on an upper case version, since upper case is all the user |
|---|
| 103 | + # can enter through the remote control. |
|---|
| 104 | + $string = uc $string; |
|---|
| 105 | + $string =~ tr/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 /AAADDDGGGJJJMMMPPPPTTTWWWW.ADGJMPTW /; |
|---|
| 106 | + return $string; |
|---|
| 107 | +} |
|---|
| 108 | + |
|---|
| 109 | +# Allow the user to put in lazy searches when adjacent characters are on the |
|---|
| 110 | +# same key without having to press right arrow or wait a while. It does this by |
|---|
| 111 | +# translating non-first keys into the right number of initial character |
|---|
| 112 | +# alternatives. |
|---|
| 113 | +# Decoding "PTNDP" ("STONES") should become "PTMMDP" |
|---|
| 114 | +# and "ODW" ("MONEY") should become "MMMDW". |
|---|
| 115 | +# |
|---|
| 116 | +# called: |
|---|
| 117 | +# undef |
|---|
| 118 | +sub lazyMultiTapDecode { |
|---|
| 119 | + my $in_string = shift; |
|---|
| 120 | + my $out_string = ""; |
|---|
| 121 | + |
|---|
| 122 | + # Loop through all the characters (back-to-front), and build up an |
|---|
| 123 | + # output string with the appropriate replacements. |
|---|
| 124 | + while ($in_string) { |
|---|
| 125 | + my $in_c = chop $in_string; |
|---|
| 126 | + my $out_c = $lazyMultiTapMap{$in_c}; |
|---|
| 127 | + $out_c = $in_c unless $out_c; |
|---|
| 128 | + $out_string = $out_c . $out_string; |
|---|
| 129 | + } |
|---|
| 130 | + |
|---|
| 131 | + return $out_string; |
|---|
| 132 | +} |
|---|
| 133 | |
|---|
| 134 | 1; |
|---|
| 135 | __END__ |
|---|