summaryrefslogtreecommitdiff
path: root/plugins/Watrack/templates/i_variables.inc
blob: a43c77b8c2e77533190624bed2ea25d5c9e02826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
{Variables support}
function GetField(ai:PARGUMENTSINFO):int_ptr; cdecl;
var
  i,j:integer;
  res,ws:pWideChar;
  s:array [0..31] of WideChar;
  rs:boolean;
  si:pSongInfo;
begin
  i:=0;
  repeat
    ws:=vars[i].alias;
    if ws=nil then
      ws:=vars[i].name;
    if lstrcmpiw(PWideChar(ai^.argv^),ws)=0 then
      break;
    inc(i);
  until i=numvars;
  ws:=nil;
  j:=-1;
  rs:=true;
  si:=pointer(CallService(MS_WAT_RETURNGLOBAL,0,0));
  case i of
    mn_wndtext: ws:=si^.wndtext;
    mn_artist : ws:=si^.artist;
    mn_title  : ws:=si^.title;
    mn_album  : ws:=si^.album;
    mn_genre  : ws:=si^.genre;
    mn_file   : begin ws:=si^.mfile; rs:=false; end;
    mn_year   : ws:=si^.year;
    mn_comment: ws:=si^.comment;
    mn_player : begin
      StrCopyW(s,si^.player);
      case PlayerCaps of
        1: LowerCase(s);
        2: UpperCase(s);
      end;
      ws:=@s;
    end;
    mn_lyric  : ws:=si^.lyric;
    mn_cover  : ws:=si^.cover;
    mn_txtver : ws:=si^.txtver;
    mn_type: begin
      GetExt(si^.mfile,s);
      if LoCaseType=BST_CHECKED then
        LowerCase(s);
//      else
//        UpperCase(s);
      ws:=@s;
    end;
    mn_size: begin
      IntToK(s,si^.fsize,FSizeMode,FSPrecision,FSizePost);
      ws:=@s;
    end;
    mn_fps: begin
      IntToStr(s,si^.fps div 100);
      ws:=@s;
      while ws^<>#0 do inc(ws);
      ws^:='.';
      IntToStr(ws+1,si^.fps mod 100);
      ws:=@s;
    end;
    mn_codec: begin
      s[0]:=WideChar( si^.codec and $FF);
      s[1]:=WideChar((si^.codec shr  8) and $FF);
      s[2]:=WideChar((si^.codec shr 16) and $FF);
      s[3]:=WideChar((si^.codec shr 24) and $FF);
      s[4]:=#0;
      ws:=@s;
    end;
    mn_vbr: if si^.vbr<>0 then
        ws:=chVBR
      else if WriteCBR<>0 then
        ws:=chCBR;
    mn_status: case si^.status of
      WAT_MES_STOPPED: ws:=TranslateW(splStopped);
      WAT_MES_PLAYING: ws:=TranslateW(splPlaying);
      WAT_MES_PAUSED : ws:=TranslateW(splPaused);
    end;
    mn_nstatus: case si^.status of
      WAT_MES_STOPPED: ws:=splStopped;
      WAT_MES_PLAYING: ws:=splPlaying;
      WAT_MES_PAUSED : ws:=splPaused;
    end;
    mn_mono: begin
      case si^.channels of
        1:   ws:=chMono;
        2:   ws:=chStereo;
        5,6: ws:=ch51;
      end;
    end;
    mn_playerhome: ws:=si^.url;
  else
    begin
      case i of
        mn_volume    : j:=loword(si^.volume);
        mn_width     : j:=si^.width;
        mn_height    : j:=si^.height;
        mn_kbps,
        mn_bitrate   : j:=si^.kbps;
        mn_khz,
        mn_samplerate: j:=si^.khz;
        mn_channels  : j:=si^.channels;
        mn_track     : j:=si^.track;
        mn_percent: begin
          if si^.total>0 then
            j:=(si^.time*100) div si^.total
          else
            j:=0;
        end;
      else
        begin
          case i of
            mn_total,
            mn_length : IntToTime(s,si^.total);
            mn_time   : IntToTime(s,si^.time);
            mn_version: IntToHex (s,si^.plyver);
          else
            result:=0;
            exit;
          end;
          ws:=@s;
        end;
      end;
    end;
  end;
  if (ws=nil) and (j>=0) then
  begin
    IntToStr(s,j);
    ws:=@s;
  end;

  StrDupW(ws,ws);
  If rs and (ReplaceSpc=BST_CHECKED) then
    CharReplaceW(ws,'_',' ');
  i:=StrLenW(ws);
  mGetMem(res,(i+1)*SizeOf(WideChar));
  if ws<>nil then
  begin
    StrCopyW(res,ws);
    mFreeMem(ws);
  end
  else
    res[0]:=#0;
  result:=int_ptr(res);
end;

function FreeField(szReturn:PAnsiChar):int; cdecl;
begin
  mFreeMem(szReturn);
  result:=1;
end;

procedure RegisterVariables;
const
  Prefix:PAnsiChar = 'WATrack'#9;
var
  rt:TTOKENREGISTER;
  i,j:integer;
  s:array [0..127] of AnsiChar;
  p:pvar;
begin
  if not isVarsInstalled then
    exit;

  rt.cbSize          :=SizeOf(rt);
  rt.memType         :=TR_MEM_OWNER;
  rt.flags           :=TRF_FIELD or TRF_CLEANUP or
                       TRF_UNICODE or TRF_PARSEFUNC or TRF_CLEANUPFUNC;
  rt.szService       :=@GetField;
  rt.szCleanupService:=@FreeField;
  j:=StrLen(Prefix);
  move(Prefix^,s,j);
  rt.szHelpText:=@s;
  for i:=0 to numvars-1 do
  begin
    p:=@vars[i];
    rt.szTokenString.w:=p.alias;
    if rt.szTokenString.w=nil then
      rt.szTokenString.w:=p.name;
    if p.help<>nil then
      StrCopy(s+j,p.help);
    CallService(MS_VARS_REGISTERTOKEN,0,lparam(@rt));
  end;
end;