summaryrefslogtreecommitdiff
path: root/plugins/mRadio/i_optdlg.inc
blob: c09e302e13d24976c4f89e1b208c804f5d73d603 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
{Options dialog}

function MakeFilter(dst,descr,full,filter:PWideChar;show:bool=true):pWideChar;
var
  p:PWideChar;
begin
  if full<>nil then
  begin
    p:=StrEndW(full);
    p^:=';';
    StrCopyW(p+1,filter);
  end;

  dst:=StrCopyEW(dst,TranslateW(descr));
  if show then
  begin
    dst^    :=' ';
    (dst+1)^:='(';
    dst:=StrCopyEW(dst+2,filter);
    dst^:=')';
    inc(dst);
    dst^:=#0;
  end;
  inc(dst);
  result:=StrCopyEW(dst,filter)+1;
end;

function ConstructFilter:pointer;
var
  pc:pWideChar;
  ph:PDWord;
  Info:PBASS_PLUGININFO;
  i:integer;
  full:array [0..511] of WideChar;
  tmpbuf1,tmpbuf2:array [0..127] of WideChar;
begin
  mGetMem(pc,4096);
//  FillChar(pc^,4096,0);
  result:=pc;
  full[0]:=#0;
  pc:=MakeFilter(pc,'All files'     ,nil ,'*.*',false);
  pc:=MakeFilter(pc,'Playlist files',full,'*.pls;*.m3u;*.m3u8;*.asx');
  pc:=MakeFilter(pc,'BASS built-in' ,full,'*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif');

  if BassStatus=rbs_null then
    MyLoadBass;

  if BassStatus<>rbs_null then
  begin
    ph:=pointer(BASS_PluginGetInfo(0));
    if ph<>nil then
    begin
      while ph^<>0 do
      begin
        Info:=BASS_PluginGetInfo(ph^);
        for i:=0 to Info^.formatc-1 do
  //!! need to translate Ansi -> wide
          with Info^.Formats[i] do
          begin
            pc:=MakeFilter(pc,FastAnsiToWideBuf(name,tmpbuf1),full,FastAnsiToWideBuf(exts,tmpbuf2));
          end;
        inc(ph);
      end;
    end;
  end;
  pc:=MakeFilter(pc,'All supported formats',nil,full,false);
  pc^:=#0;
end;

procedure SetButtonIcons(Dialog:HWND);
var
  ti:TTOOLINFOW;
  hwndTooltip:HWND;
begin
  hwndTooltip:=CreateWindowW(TOOLTIPS_CLASS,nil,TTS_ALWAYSTIP,
      integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),
      integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),
      Dialog,0,hInstance,nil);

  FillChar(ti,SizeOf(ti),0);
  ti.cbSize  :=sizeof(TOOLINFO);
  ti.uFlags  :=TTF_IDISHWND or TTF_SUBCLASS;
  ti.hwnd    :=Dialog;
  ti.hinst   :=hInstance;

  ti.uId     :=GetDlgItem(Dialog,IDC_EQ_ADD);
  ti.lpszText:=TranslateW('Add');

  SetButtonIcon(ti.uId,IcoBtnAdd);

  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_EQ_DEL);
  ti.lpszText:=TranslateW('Delete');
  SetButtonIcon(ti.uId,IcoBtnDel);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));
end;

function DlgProcOpt(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
const
  DlgInit:integer=1;
var
  buf:array [0..MAX_PATH-1] of WideChar;
  psr:TPROTOSEARCHRESULT;
  dst:pWideChar;
  i:dword;
  vhi:TVARHELPINFO;
  wnd:HWND;
  p:pWideChar;
begin
  result:=0;
  case hMessage of

    WM_INITDIALOG: begin
      DlgInit:=1;
      TranslateDialogDefault(Dialog);

      wnd:=GetDlgItem(Dialog,IDC_HLP_VARS);
      if isVarsInstalled then
      begin
        SendMessage(wnd,BM_SETIMAGE,IMAGE_ICON,
            CallService(MS_VARS_GETSKINITEM,0,VSI_HELPICON));
      end
      else
        ShowWindow(wnd,SW_HIDE);

      if recpath<>nil then
        p:=recpath
      else
      begin
        buf[0]:=#0;
        p:=@buf;
      end;
      SetDlgItemTextW(Dialog,IDC_ED_RECPATH,p);

      CheckDlgButton(Dialog,IDC_LOOP     ,doLoop);
      CheckDlgButton(Dialog,IDC_SHUFFLE  ,doShuffle);
      CheckDlgButton(Dialog,IDC_CONTREC  ,doContRec);
      CheckDlgButton(Dialog,IDC_PLAYFIRST,PlayFirst);
      CheckDlgButton(Dialog,IDC_CONNECT  ,AuConnect);
      CheckDlgButton(Dialog,IDC_AUTOMUTE ,AuMute);
      CheckDlgButton(Dialog,IDC_OFFLINE  ,AsOffline);

      SetDlgItemTextW(Dialog,IDC_STATUS,StatusTmpl);

      DlgInit:=0;
    end;

    WM_COMMAND: begin
      case wParam shr 16 of
        EN_CHANGE: begin
          if DlgInit=0 then
            case loword(wParam) of
              IDC_STATION,IDC_STATIONURL,IDC_GENRE,IDC_BITRATE: ;
            else
              SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
            end;
        end;

        BN_CLICKED: begin
          case loword(wParam) of

            IDC_IMPORT: begin
              ImportAll(0,0);
            end;

            IDC_EXPORT: begin
              ExportAll(0,0);
            end;

            IDC_HLP_VARS: begin
              FillChar(vhi,SizeOf(vhi),0);
              with vhi do
              begin
                cbSize       :=SizeOf(vhi);
                flags        :=VHF_FULLDLG or VHF_SETLASTSUBJECT;
                hwndCtrl     :=GetDlgItem(Dialog,IDC_STATUS);
                szSubjectDesc:='test your variables';
              end;
              CallService(MS_VARS_SHOWHELPEX,Dialog,tlparam(@vhi));
            end;

            IDC_BN_URLPATH: begin

              dst:=ConstructFilter;
              if ShowDlgW(@buf,nil,dst) then
                SetDlgItemTextW(Dialog,IDC_STATIONURL,@buf);
              mFreeMem(dst);
            end;

            IDC_BN_RECPATH: begin
              dst:=nil;
              if SelectDirectory(pWideChar(nil),dst,Dialog) then
              begin
                PathToRelativeW(dst,buf);
                SetDlgItemTextW(Dialog,IDC_ED_RECPATH,pWideChar(@buf));
                mFreeMem(dst);
              end;
            end;

            IDC_LOOP,IDC_SHUFFLE,IDC_CONTREC,IDC_CONNECT,IDC_OFFLINE,IDC_AUTOMUTE:
              SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);

            IDC_ADD_LIST,IDC_ADD_INI: begin
              if GetWindowTextLength(GetDlgItem(Dialog,IDC_STATIONURL))>0 then
              begin
                FillChar(psr,SizeOf(psr),0);
                with psr do
                begin
                  if loword(wParam)=IDC_ADD_LIST then
                  begin
                    GetDlgItemTextW(Dialog,IDC_STATIONURL,@buf,MAX_PATH);
                    StrDupW(firstname.w,@buf);
                    buf[0]:=#0;

                    GetDlgItemTextW(Dialog,IDC_STATION,@buf,MAX_PATH);
                    if buf[0]<>#0 then
                      StrDupW(nick.w,@buf)
                    else
                      StrDupW(nick.w,firstname.w);
                    buf[0]:=#0;

                    GetDlgItemTextW(Dialog,IDC_GENRE,@buf,MAX_PATH);
                    StrDupW(lastname.w,@buf);
                    buf[0]:=#0;

                    GetDlgItemTextW(Dialog,IDC_BITRATE,@buf,MAX_PATH);
                    StrDupW(email.w,@buf);

                    i:=Service_AddToList(0,tlparam(@psr));
{
                    GetDlgItemTextW(Dialog,IDC_STATION,@buf,SizeOf(buf));
                    DBWriteUnicode(i,strCList,optMyHandle,@buf);

                    GetDlgItemTextW(Dialog,IDC_STATIONURL,@buf,SizeOf(buf));
                    DBWriteUnicode(i,PluginName,optStationURL,@buf);
}
                    // "changing" station group
                    dst:=GetNewGroupName(Dialog);
                    if dst<>nil then
                      DBWriteUnicode(i,strCList,optGroup,dst)
                    else
                      DBDeleteSetting(i,strCList,optGroup);
                      
                  end
                  else if loword(wParam)=IDC_ADD_INI then
                  begin
                    GetDlgItemTextA(Dialog,IDC_STATIONURL,PAnsiChar(@buf),SizeOf(buf));
                    StrDup(firstname.a,PAnsiChar(@buf));
                    PAnsiChar(@buf)^:=#0;

                    GetDlgItemTextA(Dialog,IDC_STATION,PAnsiChar(@buf),SizeOf(buf));
                    if PAnsiChar(@buf)^<>#0 then
                      StrDup(nick.a,@buf)
                    else
                      StrDup(nick.a,firstname.a);
                    PAnsiChar(@buf)^:=#0;

                    GetDlgItemTextA(Dialog,IDC_GENRE,PAnsiChar(@buf),SizeOf(buf));
                    StrDup(lastname.a,@buf);
                    PAnsiChar(@buf)^:=#0;

                    GetDlgItemTextA(Dialog,IDC_BITRATE,PAnsiChar(@buf),SizeOf(buf));
                    StrDup(email.a,@buf);

                    if WritePrivateProfileStringA(firstname.a,'URL',firstname.a,storage) then
                    begin
                      WritePrivateProfileStringA(firstname.a,'Name'    ,nick.a     ,storage);
                      WritePrivateProfileStringA(firstname.a,optGenre  ,lastname.a ,storage);
                      WritePrivateProfileStringA(firstname.a,optBitrate,email.a    ,storage);
                    end
                    else
                    begin
                      WritePrivateProfileStringA(firstname.a,'URL'     ,firstname.a,storagep);
                      WritePrivateProfileStringA(firstname.a,'Name'    ,nick.a     ,storagep);
                      WritePrivateProfileStringA(firstname.a,optGenre  ,lastname.a ,storagep);
                      WritePrivateProfileStringA(firstname.a,optBitrate,email.a    ,storagep);
                    end;

                  end;
                  mFreeMem(nick);
                  mFreeMem(firstname);
                  mFreeMem(lastname);
                  mFreeMem(email);
                end;
              end;
            end;

          end;
        end;

      end;
    end;

    WM_NOTIFY: begin
      if integer(PNMHdr(lParam)^.code)=PSN_APPLY then
      begin

        doShuffle:=IsDlgButtonChecked(Dialog,IDC_SHUFFLE);
        doContRec:=IsDlgButtonChecked(Dialog,IDC_CONTREC);
        PlayFirst:=IsDlgButtonChecked(Dialog,IDC_PLAYFIRST);
        AuConnect:=IsDlgButtonChecked(Dialog,IDC_CONNECT);
        AuMute   :=IsDlgButtonChecked(Dialog,IDC_AUTOMUTE);
        AsOffline:=IsDlgButtonChecked(Dialog,IDC_OFFLINE);

        mFreeMem(StatusTmpl);
        StatusTmpl:=GetDlgText(Dialog,IDC_STATUS);

        doLoop:=IsDlgButtonChecked(Dialog,IDC_LOOP);
        if chan<>0 then
        begin
          BASS_ChannelFlags(chan,ord(doLoop<>BST_UNCHECKED),BASS_SAMPLE_LOOP);
        end;

        mFreeMem(recpath);
        buf[0]:=#0;
        GetDlgItemTextW(Dialog,IDC_ED_RECPATH,@buf,SizeOf(buf) div SizeOf(WideChar));
        if buf[0]<>#0 then
        begin
          mGetMem(recpath,MAX_PATH*SizeOf(WideChar));
          recpath^:=#0;
          PathToRelativeW(buf,recpath);
        end
        else
          recpath:=GetDefaultRecPath;

        SaveCommonSettings;
      end;
    end;

//  else
//    result:=DefWindowProc(Dialog,hMessage,wParam,lParam);
  end;
end;

//----- Tech tab -----

procedure FillDeviceCombo(wnd:HWND;choose:pAnsiChar);
var
  i,select,def:integer;
  info:BASS_DEVICEINFO;
  buf: array [0..255] of AnsiChar;
begin
  def:=0;
  SendMessage(wnd,CB_RESETCONTENT,0,0);
  if BassStatus<>rbs_null then
  begin
    i:=0;
    select:=-1;
    repeat
      if not BASS_GetDeviceInfo(i+1,info) then
        break;
      if (info.flags and BASS_DEVICE_ENABLED)<>0 then
      begin
        if (info.flags and BASS_DEVICE_INIT)<>0 then
        begin
          select:=i;
          buf[0]:='>';
        end
        else if (info.flags and BASS_DEVICE_DEFAULT)<>0 then
        begin
          def:=i;
          buf[0]:='*';
        end
        else buf[0]:=' ';
        if select<0 then
        begin
          if StrCmp(info.name,choose)=0 then
            select:=i;
        end;
        StrCopy(@buf[1],info.name);
        SendMessageA(wnd,CB_ADDSTRING,0,lparam(@buf));
      end;
      inc(i);
    until false;
    if select>=0 then
      def:=select;
  end;
  SendMessage(wnd,CB_SETCURSEL,def,0);
end;

function DlgProcOptTech(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
const
  DlgInit:integer=1;
var
  hEAXCombo:THANDLE;
  ltmp:longbool;
  wnd:HWND;
  buf:array [0..MAX_PATH-1] of WideChar;
  dst,old:pWideChar;
  device:pAnsiChar;
  i,level:integer;
begin
  result:=0;
  case hMessage of
    WM_DESTROY: begin
      hVolCtrl:=0;

      for i:=0 to 9 do
      begin
        eq[i].wnd:=0;
      end;
    end;

    WM_INITDIALOG: begin
      DlgInit:=1;
      TranslateDialogDefault(Dialog);

      SetButtonIcons(Dialog);
      hVolCtrl:=GetDlgItem(Dialog,IDC_VOLUME);
      SendMessage(hVolCtrl,TBM_SETRANGE,0,(100 shl 16)+0);
      SendMessage(hVolCtrl,TBM_SETPOS,1,ABS(gVolume));

      SetDlgItemInt(Dialog,IDC_BUFFER ,sBuffer ,false);
      SetDlgItemInt(Dialog,IDC_PREBUF ,sPreBuf ,false);
      SetDlgItemInt(Dialog,IDC_TIMEOUT,sTimeout,false);
      SetDlgItemInt(Dialog,IDC_TRIES  ,NumTries,false);

      CheckDlgButton(Dialog,IDC_MONO,ForcedMono);

      // Fill EAX combo
      hEAXCombo:=GetDlgItem(Dialog,IDC_EAXTYPE);
      for i:=0 to EAX_ENVIRONMENT_COUNT do
        SendMessageW(hEAXCombo,CB_ADDSTRING,0,tlparam(TranslateW(EAXItems[i].name)));
      SendMessage(hEAXCombo,CB_SETCURSEL,DBReadByte(0,PluginName,optEAXType,0),0);

      if BassStatus=rbs_null then
        MyLoadBass;
      // Fill combo with devices
      FillDeviceCombo(GetDlgItem(Dialog,IDC_DEVICE),usedevice);

      // Add preset to combo
      wnd:=GetDlgItem(Dialog,IDC_PRESET);

      for i:=0 to HIGH(Presets) do
        SendMessageW(wnd,CB_ADDSTRING,0,tlparam(Presets[i].name));
      SendMessage(wnd,CB_SETCURSEL,OldEQPreset,0);

      // Equalizer
      for i:=0 to 9 do
      begin
        eq[i].wnd:=GetDlgItem(Dialog,IDC_EQ00+i);
        SendMessage(eq[i].wnd,TBM_SETRANGE,1,(16 shl 16)-15);
        SendMessage(eq[i].wnd,TBM_SETTIC,0,0);
        SendMessage(eq[i].wnd,TBM_SETPOS,1,-trunc(eq[i].param.fGain));
        SendDlgItemMessageA(Dialog,IDC_0+i,WM_SETTEXT,0,tlparam(eq[i].text));
        EnableWindow(eq[i].wnd,isEQ_OFF=BST_UNCHECKED);
      end;
      
      CheckDlgButton(Dialog,IDC_EQOFF,isEQ_OFF);

      dst:=DBReadUnicode(0,PluginName,optBASSPath,nil);
      SetDlgItemTextW(Dialog,IDC_BASSPATH,dst);
      mFreeMem(dst);

      DlgInit:=0;
    end;

    WM_COMMAND: begin
      case wParam shr 16 of
        EN_CHANGE: begin
          if DlgInit=0 then
            SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
        end;

        BN_CLICKED: begin
          case loword(wParam) of
            IDC_EQOFF, IDC_ZERO:
              SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
          end;

          case loword(wParam) of

            IDC_BASSPTHBTN: begin
              dst:=nil;
              if SelectDirectory(pWideChar(nil),dst,Dialog) then
              begin
                PathToRelativeW(dst,buf);
                SetDlgItemTextW(Dialog,IDC_BASSPATH,pWideChar(@buf));
                mFreeMem(dst);
              end;
            end;

            IDC_EQOFF: begin
              isEQ_OFF:=IsDlgButtonChecked(Dialog,IDC_EQOFF);
              if isEQ_OFF=BST_UNCHECKED then
                EQ_ON
              else
                EQ_OFF;

              for i:=0 to 9 do
                EnableWindow(eq[i].wnd,isEQ_OFF=BST_UNCHECKED);
            end;

            IDC_ZERO: begin
              OldEQPreset:=-1;
              for i:=0 to 9 do
              begin
                eq[i].param.fGain:=0;
                SendMessage(eq[i].wnd,TBM_SETPOS,1,0);
                if (chan<>0) and (isEQ_OFF=BST_UNCHECKED) then
                  BASS_FXSetParameters(eq[i].fx,@eq[i].param);
              end;
            end;

            IDC_EQ_ADD: begin
              SetLength(Presets,Length(Presets)+1);

              for i:=0 to 9 do
                Presets[HIGH(Presets)].preset[i]:=-SendMessage(eq[i].wnd,TBM_GETPOS,0,0);

              wnd:=GetDlgItem(Dialog,IDC_PRESET);
              Presets[HIGH(Presets)].name:=GetDlgText(wnd,false);
              if Presets[HIGH(Presets)].name=nil then
                StrDupW(Presets[HIGH(Presets)].name,'New');
              OldEQPreset:=SendMessage(wnd,CB_SETCURSEL,
                SendMessageW(wnd,CB_ADDSTRING,0,tlparam(Presets[HIGH(Presets)].name)),0);
            end;

            IDC_EQ_DEL: begin
              wnd:=GetDlgItem(Dialog,IDC_PRESET);
              i:=SendMessage(wnd,CB_GETCURSEL,0,0);
              if (i>=0) and (i<=HIGH(Presets)) then
              begin
                SendMessage(wnd,CB_DELETESTRING,i,0);
                mFreeMem(Presets[i].name);
                move(Presets[i+1],Presets[i],(HIGH(Presets)-i)*SizeOf(tPreset));
                SetLength(Presets,Length(Presets)-1);
                OldEQPreset:=-1;
                SendMessage(wnd,CB_SETCURSEL,-1,0);
              end;
            end;

          end;
        end;

        CBN_SELCHANGE: begin
          SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
          case loword(wParam) of
            IDC_PRESET: begin
              OldEQPreset:=SendDlgItemMessage(Dialog,IDC_PRESET,CB_GETCURSEL,0,0);
              for i:=0 to 9 do
              begin
                SendMessage(eq[i].wnd,TBM_SETPOS,1,-Presets[OldEQPreset].preset[i]);
                eq[i].param.fGain:=Presets[OldEQPreset].preset[i];
                if (chan<>0) and (isEQ_OFF=BST_UNCHECKED) then
                  BASS_FXSetParameters(eq[i].fx,@eq[i].param);
              end;
            end;
            IDC_EAXTYPE: begin
{
              i:=SendDlgItemMessage(Dialog,IDC_EAXTYPE,CB_GETCURSEL,0,0);
              DBWriteByte(0,PluginName,optEAXType,i);
              if i=0 then
                BASS_SetEAXParameters(-1,0,-1,-1)
              else
                BASS_SetEAXPreset(EAXItems[i].code);
}
            end;
          end;
        end;
      end;
    end;

    WM_VSCROLL: begin
      for i:=0 to 9 do
      begin
        if HWND(lParam)=eq[i].wnd then
        begin
          eq[i].param.fGain:=-SendMessage(lParam,TBM_GETPOS,0,0);
          if (chan<>0) and (isEQ_OFF=BST_UNCHECKED) then
            BASS_FXSetParameters(eq[i].fx,@eq[i].param);
          OldEQPreset:=-1;
          break;
        end;
      end;
      SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
    end;

    WM_HSCROLL: begin
       Service_RadioSetVolume(SendMessage(lParam,TBM_GETPOS,0,0),1)
    end;

    WM_NOTIFY: begin
      if integer(PNMHdr(lParam)^.code)=PSN_APPLY then
      begin
        SavePresets;
        level:=0;

        device:=GetDlgText(Dialog,IDC_DEVICE,true);
        StrCopy(device,device+1);
        if StrCmp(usedevice,device)<>0 then
        begin
          level:=1;
          mFreeMem(usedevice);
          usedevice:=device;
        end
        else
          mFreeMem(device);

//!!  bass path saving here
        old:=DBReadUnicode(0,PluginName,optBASSPath,nil);
        dst:=GetDlgText(Dialog,IDC_BASSPATH);
        if lstrcmpiw(dst,old)<>0 then
        begin
          level:=2;
          DBWriteUnicode(0,PluginName,optBASSPath,dst);
        end;
        mFreeMem(dst);
        mFreeMem(old);

        i:=SendDlgItemMessage(Dialog,IDC_EAXTYPE,CB_GETCURSEL,0,0);
        DBWriteByte(0,PluginName,optEAXType,i);

{
  level>0 - need to change
  ActiveContact<>0 - need to restart
  BassStatus<>rbs_null - need to stop (free, unload)
  really,  if ActiveContact<>0 then BassStatus<>rbs_null
}
        //!!really, need to do it if only active atm
        // need to reload dll or change outpout device
        // don't change proxy
        if level>0 then
        begin
          ltmp:=ActiveContact<>0;
          if ltmp then
            CallService(MS_RADIO_COMMAND,MRC_STOP,1);
          // save current, stop, bass free

          MyFreeBass;
          if level=2 then
          begin
            MyUnloadBass;
            // load dll
            if ltmp then
              MyLoadBass;
          end;
          // init device, restore current
          if ltmp and (BassStatus=rbs_load) then
          begin
            MyInitBass;
          end;
          if ltmp and (BassStatus=rbs_init) then
          begin
            CallService(MS_RADIO_COMMAND,MRC_PAUSE,0);
          end;
        end
        // if device re-init, EAX settings applied there
        else if BassStatus=rbs_init then
        begin
          if i=0 then
            BASS_SetEAXParameters(-1,0,-1,-1)
          else
            BASS_SetEAXPreset(EAXItems[i].code);
        end;


        ForcedMono:=IsDlgButtonChecked(Dialog,IDC_MONO);

        NumTries:=GetDlgItemInt(Dialog,IDC_TRIES,ltmp,false);
        if NumTries<1 then NumTries:=1;

        // Bass config settings

        sPreBuf:=GetDlgItemInt(Dialog,IDC_PREBUF,ltmp,false);
        if sPreBuf>100 then sPreBuf:=100;

        sBuffer:=GetDlgItemInt(Dialog,IDC_BUFFER,ltmp,false);
        if sBuffer>20000 then sBuffer:=20000;

        sTimeout:=GetDlgItemInt(Dialog,IDC_TIMEOUT,ltmp,false);
        if sTimeout>30000 then sTimeout:=30000;

        SetBassConfig;

        SaveTechSettings;
      end;
    end;

//  else
//    result:=DefWindowProc(Dialog,hMessage,wParam,lParam);
  end;
end;

function OnOptInitialise(wParam:WPARAM;lParam:LPARAM):int;cdecl;
var
  odp:TOPTIONSDIALOGPAGE;
begin
  FillChar(odp,SizeOf(odp),0);
  odp.cbSize     :=SizeOf(odp);
  odp.flags      :=ODPF_BOLDGROUPS;
  odp.Position   :=900003000;
  odp.hInstance  :=hInstance;
  odp.szGroup.a  :='Network';
  odp.szTitle.a  :=PluginName;

  odp.pszTemplate:=MAKEINTRESOURCEA(IDD_SETTING);
  odp.pfnDlgProc :=@DlgProcOpt;
  odp.szTab.a    :='Common';
  CallService(MS_OPT_ADDPAGE,wParam,tlparam(@odp));

  odp.pszTemplate:=MAKEINTRESOURCEA(IDD_SETTING_TECH);
  odp.pfnDlgProc :=@DlgProcOptTech;//!!
  odp.szTab.a    :=Translate('Advanced');
  CallService(MS_OPT_ADDPAGE,wParam,tlparam(@odp));

  result:=0;
end;

// checking proto in several places for speed, not size economy
function OnSettingsChanged(wParam:WPARAM;lParam:LPARAM):int;cdecl;
var
  buf:array [0..MAX_PATH-1] of AnsiChar;
  i:integer;
  pc:PAnsiChar;
begin
  result:=0;

  with PDBCONTACTWRITESETTING(lParam)^ do
  begin

    if AuMute<>BST_UNCHECKED then
    begin
      if StrCmp(szModule,'Skin')=0 then
      begin
        if StrCmp(szSetting,'UseSound')=0 then
        begin
          // Mute
          if value.bVal=0 then
          begin
            if gVolume>=0 then
              Service_RadioMute(0,0);
          end
          // Unmute
          else
          begin
            if gVolume<0 then
              Service_RadioMute(0,0);
          end;
        end;

        exit;
      end
    end;

    // works only if called AFTER changes
    if StrCmp(szModule,strCList)=0 then
    begin
      if StrCmp(szSetting,optMyHandle)=0 then
      begin
        if value._type=DBVT_DELETED then
        begin
          if StrCmp(PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0)),
             PluginName)<>0 then exit;

          pc:=DBReadString(wParam,PluginName,optNick);
          DBWriteString(wParam,strCList,optMyHandle,pc);
          mFreeMem(pc);
        end;
      end;
      exit;
    end;

    if StrCmp(szModule,'UserInfo')<>0 then exit;

    if StrCmp(szSetting,optAge)=0 then
    begin
      if StrCmp(PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0)),
         PluginName)<>0 then exit;
      if value._type=DBVT_DELETED then
        i:=DBReadWord(wParam,PluginName,optAge)
      else
        i:=value.wVal;
      DBWriteString(wParam,PluginName,optBitrate,IntToStr(buf,i));
      exit;
    end;

    case value._type of
      DBVT_DELETED,
      DBVT_ASCIIZ ,
      DBVT_WCHAR  ,
      DBVT_UTF8   :
      if StrCmp(PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0)),
         PluginName)<>0 then exit;
    else
      exit;
    end;

    case value._type of
      DBVT_DELETED: pc:=DBReadString(wParam,PluginName,szSetting);
      DBVT_ASCIIZ : pc:=value.szVal.a;
      DBVT_WCHAR  : WideToAnsi(value.szVal.w,pc,MirandaCP);
      DBVT_UTF8   : UTF8ToAnsi(value.szVal.a,pc,MirandaCP);
    end;

    if      StrCmp(szSetting,optFirstName)=0 then DBWriteString(wParam,PluginName,optStationURL,pc)
    else if StrCmp(szSetting,optNick     )=0 then DBWriteString(wParam,strCList,optMyHandle,pc)
    else if StrCmp(szSetting,optLastName )=0 then DBWriteString(wParam,PluginName,optGenre,pc);

    if value._type<>DBVT_ASCIIZ then
      mFreeMem(pc);
  end;
end;

function OnContactDeleted(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  result:=0;
  if ActiveContact<>THANDLE(wParam) then exit;
  ControlCenter(MRC_STOP,wParam);

{  if StrCmp(PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0)),
             PluginName)<>0 then exit;
}
end;