www.pudn.com > TMIDIPlayer_w_MidiSheet.rar > ViewChannel_D7.pas, change:2013-02-11,size:33835b


{ UNIT ViewChannel.pas 
--------------------------------- ViewChannel ----------------------------- 
 This unit takes charge of displaying channel window for kMIDIPlayer 
 
 Copyright 2011 Silhwan Hyun, All Rights Reserved 
 
 
 Author : Silhwan Hyun   (e-mail addr : hyunsh@hanafos.com) 
 
 Contibutors 
   Emil Weiss : Test & Advice for update/debug 
 
 Revision History 
 ------------------------------ 
  Ver 0.9.0    9 Feb 2013 
    - Initial Release 
 
----------------------------------------------------------------------------} 
 
unit ViewChannel_D7; 
 
{$DEFINE MULTI_LANGUAGE} 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, MIDIFile2, MidiPlayer2, Instrument, Buttons, 
  {$IFDEF MULTI_LANGUAGE}gnugettext,{$ENDIF} AMLed, ExtCtrls, AdvImage, pngimage; 
 
const 
  WM_ViewChannelConfig = WM_USER + 147; 
  ViewChannel_Shown     = 1; 
  ViewChannel_Closed    = 2; 
 
type 
  TViewChannelForm = class(TForm) 
    btnClose: TButton; 
    AdvImage1: TAdvImage; 
    chImageBtn1: TAdvImage; 
    chImageBtn2: TAdvImage; 
    chImageBtn4: TAdvImage; 
    chImageBtn3: TAdvImage; 
    chImageBtn5: TAdvImage; 
    chImageBtn6: TAdvImage; 
    chImageBtn8: TAdvImage; 
    chImageBtn7: TAdvImage; 
    chImageBtn9: TAdvImage; 
    chImageBtn10: TAdvImage; 
    chImageBtn13: TAdvImage; 
    chImageBtn11: TAdvImage; 
    chImageBtn12: TAdvImage; 
    chImageBtn14: TAdvImage; 
    chImageBtn16: TAdvImage; 
    chImageBtn15: TAdvImage; 
    Led_CH1: TLed; 
    Led_CH2: TLed; 
    Led_CH4: TLed; 
    Led_CH3: TLed; 
    Led_CH8: TLed; 
    Led_CH7: TLed; 
    Led_CH6: TLed; 
    Led_CH5: TLed; 
    Led_CH16: TLed; 
    Led_CH15: TLed; 
    Led_CH14: TLed; 
    Led_CH13: TLed; 
    Led_CH12: TLed; 
    Led_CH11: TLed; 
    Led_CH10: TLed; 
    Led_CH9: TLed; 
    FaderThumb1: TAdvImage; 
    lblInst1: TLabel; 
    lblInst2: TLabel; 
    lblInst3: TLabel; 
    lblInst4: TLabel; 
    lblInst7: TLabel; 
    lblInst8: TLabel; 
    lblInst6: TLabel; 
    lblInst5: TLabel; 
    lblInst15: TLabel; 
    lblInst16: TLabel; 
    lblInst14: TLabel; 
    lblInst13: TLabel; 
    lblInst12: TLabel; 
    lblInst11: TLabel; 
    lblInst10: TLabel; 
    lblInst9: TLabel; 
    lblFader1: TLabel; 
    lblFader2: TLabel; 
    lblFader3: TLabel; 
    lblFader4: TLabel; 
    lblFader7: TLabel; 
    lblFader8: TLabel; 
    lblFader6: TLabel; 
    lblFader5: TLabel; 
    lblFader15: TLabel; 
    lblFader16: TLabel; 
    lblFader14: TLabel; 
    lblFader13: TLabel; 
    lblFader12: TLabel; 
    lblFader11: TLabel; 
    lblFader10: TLabel; 
    lblFader9: TLabel; 
    FaderThumb2: TAdvImage; 
    FaderThumb3: TAdvImage; 
    FaderThumb4: TAdvImage; 
    FaderThumb5: TAdvImage; 
    FaderThumb6: TAdvImage; 
    FaderThumb7: TAdvImage; 
    FaderThumb8: TAdvImage; 
    FaderThumb9: TAdvImage; 
    FaderThumb10: TAdvImage; 
    FaderThumb11: TAdvImage; 
    FaderThumb12: TAdvImage; 
    FaderThumb13: TAdvImage; 
    FaderThumb14: TAdvImage; 
    FaderThumb15: TAdvImage; 
    FaderThumb16: TAdvImage; 
    btn_Solo1: TAdvImage; 
    btn_Solo2: TAdvImage; 
    btn_Solo3: TAdvImage; 
    btn_Solo4: TAdvImage; 
    btn_Solo5: TAdvImage; 
    btn_Solo6: TAdvImage; 
    btn_Solo7: TAdvImage; 
    btn_Solo8: TAdvImage; 
    btn_Solo9: TAdvImage; 
    btn_Solo10: TAdvImage; 
    btn_Solo11: TAdvImage; 
    btn_Solo12: TAdvImage; 
    btn_Solo13: TAdvImage; 
    btn_Solo14: TAdvImage; 
    btn_Solo15: TAdvImage; 
    btn_Solo16: TAdvImage; 
    RadioGroup1: TRadioGroup; 
    rbDelay: TRadioButton; 
    rbChorus: TRadioButton; 
    rbReverb: TRadioButton; 
    rbExpression: TRadioButton; 
    rbPan: TRadioButton; 
    rbVolume: TRadioButton; 
    RadioGroup2: TRadioGroup; 
    cbMIDIMode: TComboBox; 
    btnReset: TButton; 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Label5: TLabel; 
    Label6: TLabel; 
    Label7: TLabel; 
    Label8: TLabel; 
    btnAllOn: TButton; 
    procedure btnCloseClick(Sender: TObject); 
    procedure btnSolo_NClick(Sender: TObject); 
    procedure btnAllOnClick(Sender: TObject); 
    procedure cb_CHNClick(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure FormShow(Sender: TObject); 
    procedure FormClose(Sender: TObject; var Action: TCloseAction); 
    procedure cbMIDIModeChange(Sender: TObject); 
    procedure rbFaderSelClick(Sender: TObject); 
    procedure btnResetClick(Sender: TObject); 
    procedure FormDestroy(Sender: TObject); 
    procedure chImageBtnMouseEnter(Sender: TObject); 
    procedure chImageBtnMouseLeave(Sender: TObject); 
    procedure chImageBtnMouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure chImageBtnMouseUp(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure FaderThumbMouseMove(Sender: TObject; Shift: TShiftState; X, 
      Y: Integer); 
  private 
    { Private declarations } 
    procedure SetInstrumentName(MIDIMode: TMIDIMode; ChannelNo, Bank, ProgramNo: byte); 
    procedure SetSlidePos(ChannelNo, FaderVal: byte); 
    procedure SetFaderVal(ChannelNo, FaderVal: byte; BySlider: boolean); 
    procedure SetImageBtn(img: TAdvImage); 
    procedure SetImage(Destination: TAdvImage; 
                                x, y, W, H: integer; 
                                Source: TBitmap; 
                                startX, StartY: integer); 
    procedure BtnImageLoad(Btn_No : integer; b_Pressed, b_Highlighted : boolean); 
  public 
    { Public declarations } 
    procedure ResetInstrumentFields; 
    procedure ResetExpressions; 
    procedure ResetFields(Reset_Device: boolean); 
    procedure GetChannelEvent(MidiEvent: TMidiEvent); 
    procedure SetPlayerChannelState; 
  end; 
 
var 
  ViewChannelForm: TViewChannelForm; 
 
 
implementation 
 
{$R *.dfm} 
 
uses MIDITest; 
 
const 
  OnInterval = 40; 
 
  ThumbLeftPos = 407; 
  ThumbTravel = 68; 
 
var 
  BankData: array[1..16] of byte = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); 
  MapData: array[1..16] of byte = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); 
  VolumeData: array[1..16] of byte; 
  PanData: array[1..16] of byte; 
  ExpressionData: array[1..16] of byte; 
  ReverbData: array[1..16] of byte; 
  ChorusData: array[1..16] of byte; 
  DelayData: array[1..16] of byte; 
 
  ChannelState: TChannelState; 
  MIDI_Mode: TMIDIMode = GS; 
  MovingSliderNo: integer = 0; 
  FaderType: TFaderType = fVolume; 
 
  Image_Controls: TBitmap; 
  i_CursorOn: integer = 0; 
  b_BtnPressed: boolean = false; 
 
  CURSOR_HAND: HCURSOR; 
  NowTracking: boolean = false; 
  ThumbStartX: integer; 
  ThumbMouseDownX : integer; 
 
 
procedure TViewChannelForm.ResetInstrumentFields; 
var 
  I: integer; 
begin 
  for I := 1 to 16 do 
  begin 
    BankData[I] := 0; 
    MapData[I] := 0; 
  end; 
 
  lblInst1.Caption := 'Piano 1'; 
  lblInst2.Caption := 'Piano 1'; 
  lblInst3.Caption := 'Piano 1'; 
  lblInst4.Caption := 'Piano 1'; 
  lblInst5.Caption := 'Piano 1'; 
  lblInst6.Caption := 'Piano 1'; 
  lblInst7.Caption := 'Piano 1'; 
  lblInst8.Caption := 'Piano 1'; 
  lblInst9.Caption := 'Piano 1'; 
  lblInst10.Caption := 'STANDARD 1'; 
  lblInst11.Caption := 'Piano 1'; 
  lblInst12.Caption := 'Piano 1'; 
  lblInst13.Caption := 'Piano 1'; 
  lblInst14.Caption := 'Piano 1'; 
  lblInst15.Caption := 'Piano 1'; 
  lblInst16.Caption := 'Piano 1'; 
end; 
 
procedure TViewChannelForm.ResetExpressions; 
var 
  I: integer; 
begin 
  for I := 1 to 16 do 
  begin 
    ExpressionData[I] := 127; 
    MainForm.MidiPlayer.SetChannelFader(I - 1, 127, fExpression); 
  end; 
 
  if FaderType = fExpression then 
  begin 
    for I := 1 to 16 do 
      SetSlidePos(I, 127); 
    lblFader1.Caption := '127'; 
    lblFader2.Caption := '127'; 
    lblFader3.Caption := '127'; 
    lblFader4.Caption := '127'; 
    lblFader5.Caption := '127'; 
    lblFader6.Caption := '127'; 
    lblFader7.Caption := '127'; 
    lblFader8.Caption := '127'; 
    lblFader9.Caption := '127'; 
    lblFader10.Caption := '127'; 
    lblFader11.Caption := '127'; 
    lblFader12.Caption := '127'; 
    lblFader13.Caption := '127'; 
    lblFader14.Caption := '127'; 
    lblFader15.Caption := '127'; 
    lblFader16.Caption := '127'; 
  end; 
end; 
 
procedure TViewChannelForm.ResetFields(Reset_Device: boolean); 
var 
  I: integer; 
begin 
  for I := 1 to 16 do 
  begin 
  //  BankData[I] := 0; 
  //  MapData[I] := 0; 
    VolumeData[I] := 127; 
    ExpressionData[I] := 127; 
    PanData[I] := 64; 
    ReverbData[I] := 40; 
    ChorusData[I] := 0; 
    DelayData[I] := 0; 
  end; 
 
  ResetInstrumentFields; 
 
  for I := 0 to Self.ComponentCount - 1 do 
    if Self.Components[I] is TLabel then 
    begin 
      if (Self.Components[I].Tag >= 1) and (Self.Components[I].Tag <= 16) then 
      begin 
        if copy(Self.Components[I].Name, 1, 8) = 'lblFader' then 
        begin 
          if rbVolume.Checked or rbExpression.Checked then 
            (Self.Components[I] as TLabel).Caption := '127' 
          else if rbPan.Checked then 
            (Self.Components[I] as TLabel).Caption := '64' 
          else if rbReverb.Checked then 
            (Self.Components[I] as TLabel).Caption := '40' 
          else if rbDelay.Checked or rbChorus.Checked then 
            (Self.Components[I] as TLabel).Caption := '0'; 
        end; 
      end; 
    end else 
    if Self.Components[I] is TAdvImage then 
    begin 
      if (Self.Components[I].Tag >= 21) and (Self.Components[I].Tag <= 36) then 
      begin 
        if rbVolume.Checked or rbExpression.Checked then 
          (Self.Components[I] as TAdvImage).Left := ThumbLeftPos + ThumbTravel 
        else if rbPan.Checked then 
          (Self.Components[I] as TAdvImage).Left := ThumbLeftPos + round(ThumbTravel * 64 / 127) 
        else if rbReverb.Checked then 
          (Self.Components[I] as TAdvImage).Left := ThumbLeftPos + round(ThumbTravel * 40 / 127) 
        else if rbDelay.Checked or rbChorus.Checked then 
          (Self.Components[I] as TAdvImage).Left := ThumbLeftPos; 
      end; 
    end; 
 // ListBox1.Clear; 
 
  if Reset_Device then 
    MainForm.MidiPlayer.ResetDevice(MIDI_Mode); 
end; 
 
function GetDrumKitName(KitNo: byte): string; 
begin 
  case KitNo of 
       1 : Result := 'STANDARD 1'; 
       2 : Result := 'STANDARD 2'; 
       3 : Result := 'STANDARD 3'; 
       9 : Result := 'Room'; 
      10 : Result := 'Hip-Hop'; 
      11 : Result := 'Jungle'; 
      12 : Result := 'Techno'; 
      17 : Result := 'Power'; 
      25 : Result := 'Electronic'; 
      26 : Result := 'TR-808'; 
      27 : Result := 'Dance'; 
      28 : Result := 'CR-78'; 
      29 : Result := 'TR-606'; 
      30 : Result := 'TR-707'; 
      31 : Result := 'TR-909'; 
      33 : Result := 'Jazz'; 
      41 : Result := 'Brush'; 
      49 : Result := 'Orchestra'; 
      51 : Result := 'Ethnic'; 
      52 : Result := 'Kick & Snare'; 
      53 : Result := 'Asia'; 
      54 : Result := 'Cymbal & Claps'; 
      57 : Result := 'Sound FX'; 
      58 : Result := 'Rhythm FX 1'; 
      59 : Result := 'Rhythm FX 2'; 
     128 : Result := 'CM-64/CM-32L'; 
    else 
      Result := 'Unknown Drum Kit (Kit # : ' + intToStr(KitNo) + ')'; 
  end; 
end; 
 
procedure TViewChannelForm.SetInstrumentName(MIDIMode: TMIDIMode; ChannelNo, Bank, ProgramNo: byte); 
begin 
  case ChannelNo of 
    1 : lblInst1.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    2 : lblInst2.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    3 : lblInst3.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    4 : lblInst4.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    5 : lblInst5.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    6 : lblInst6.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    7 : lblInst7.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    8 : lblInst8.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
    9 : lblInst9.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
   10 : lblInst10.Caption := GetDrumKitName(ProgramNo + 1); 
   11 : lblInst11.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
   12 : lblInst12.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
   13 : lblInst13.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
   14 : lblInst14.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
   15 : lblInst15.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
   16 : lblInst16.Caption := GetProgramName(MIDIMode, Bank, ProgramNo); 
  end; 
end; 
 
procedure TViewChannelForm.SetSlidePos(ChannelNo, FaderVal: byte); 
begin 
  case ChannelNo of 
     1 : FaderThumb1.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     2 : FaderThumb2.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     3 : FaderThumb3.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     4 : FaderThumb4.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     5 : FaderThumb5.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     6 : FaderThumb6.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     7 : FaderThumb7.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     8 : FaderThumb8.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
     9 : FaderThumb9.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    10 : FaderThumb10.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    11 : FaderThumb11.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    12 : FaderThumb12.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    13 : FaderThumb13.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    14 : FaderThumb14.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    15 : FaderThumb15.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
    16 : FaderThumb16.Left := ThumbLeftPos + round(ThumbTravel * FaderVal / 127); 
  end; 
end; 
 
procedure TViewChannelForm.SetFaderVal(ChannelNo, FaderVal: byte; BySlider: boolean); 
begin 
  case ChannelNo of 
     1 : lblFader1.Caption := intToStr(FaderVal); 
     2 : lblFader2.Caption := intToStr(FaderVal); 
     3 : lblFader3.Caption := intToStr(FaderVal); 
     4 : lblFader4.Caption := intToStr(FaderVal); 
     5 : lblFader5.Caption:= intToStr(FaderVal); 
     6 : lblFader6.Caption:= intToStr(FaderVal); 
     7 : lblFader7.Caption := intToStr(FaderVal); 
     8 : lblFader8.Caption := intToStr(FaderVal); 
     9 : lblFader9.Caption := intToStr(FaderVal); 
    10 : lblFader10.Caption := intToStr(FaderVal); 
    11 : lblFader11.Caption := intToStr(FaderVal); 
    12 : lblFader12.Caption := intToStr(FaderVal); 
    13 : lblFader13.Caption := intToStr(FaderVal); 
    14 : lblFader14.Caption := intToStr(FaderVal); 
    15 : lblFader15.Caption := intToStr(FaderVal); 
    16 : lblFader16.Caption := intToStr(FaderVal); 
  end; 
 
  case FaderType of 
    fVolume : VolumeData[ChannelNo] := FaderVal; 
    fPan : PanData[ChannelNo] := FaderVal; 
    fExpression : ExpressionData[ChannelNo] := FaderVal; 
    fReverb : ReverbData[ChannelNo] := FaderVal; 
    fChorus : ChorusData[ChannelNo] := FaderVal; 
    fDelay : DelayData[ChannelNo] := FaderVal; 
  end; 
 
  if not BySlider then 
    SetSlidePos(ChannelNo, FaderVal); 
end; 
 
procedure TViewChannelForm.SetPlayerChannelState; 
begin 
  MainForm.MidiPlayer.ChannelState := ChannelState; 
end; 
 
procedure TViewChannelForm.btnAllOnClick(Sender: TObject); 
var 
  I: integer; 
begin 
  for I := 0 to 15 do 
  begin 
    ChannelState[I] := true; 
    BtnImageLoad(I+1, false, false); 
  end; 
  SetPlayerChannelState; 
end; 
 
procedure TViewChannelForm.btnCloseClick(Sender: TObject); 
begin 
   Close; 
end; 
 
procedure TViewChannelForm.btnResetClick(Sender: TObject); 
begin 
  ResetFields(true); 
end; 
 
procedure TViewChannelForm.btnSolo_NClick(Sender: TObject); 
var 
  BtnNo: integer; 
  I: integer; 
begin 
  BtnNo := (Sender as TAdvImage).Tag; 
  if BtnNo = 41 then ChannelState[0] := true else ChannelState[0] := false; 
  if BtnNo = 42 then ChannelState[1] := true else ChannelState[1] := false; 
  if BtnNo = 43 then ChannelState[2] := true else ChannelState[2] := false; 
  if BtnNo = 44 then ChannelState[3] := true else ChannelState[3] := false; 
  if BtnNo = 45 then ChannelState[4] := true else ChannelState[4] := false; 
  if BtnNo = 46 then ChannelState[5] := true else ChannelState[5] := false; 
  if BtnNo = 47 then ChannelState[6] := true else ChannelState[6] := false; 
  if BtnNo = 48 then ChannelState[7] := true else ChannelState[7] := false; 
  if BtnNo = 49 then ChannelState[8] := true else ChannelState[8] := false; 
  if BtnNo = 50 then ChannelState[9] := true else ChannelState[9] := false; 
  if BtnNo = 51 then ChannelState[10] := true else ChannelState[10] := false; 
  if BtnNo = 52 then ChannelState[11] := true else ChannelState[11] := false; 
  if BtnNo = 53 then ChannelState[12] := true else ChannelState[12] := false; 
  if BtnNo = 54 then ChannelState[13] := true else ChannelState[13] := false; 
  if BtnNo = 55 then ChannelState[14] := true else ChannelState[14] := false; 
  if BtnNo = 56 then ChannelState[15] := true else ChannelState[15] := false; 
 
  for I := 1 to 16 do 
    BtnImageLoad(I, false, false); 
  SetPlayerChannelState; 
end; 
 
procedure TViewChannelForm.cb_CHNClick(Sender: TObject); 
begin 
  BtnImageLoad((Sender as TSpeedButton).Tag, false, false); 
  SetPlayerChannelState; 
end; 
 
procedure TViewChannelForm.SetImageBtn(img: TAdvImage); 
begin 
 { img.OnMouseEnter := ImageMouseEnter; 
  img.OnMouseLeave := ImageMouseLeave; } 
 
  img.Picture.Bitmap.Width := img.Width; 
  img.Picture.Bitmap.Height := img.Height; 
end; 
 
procedure TViewChannelForm.SetImage(Destination: TAdvImage; 
                                x, y, W, H: integer; 
                                Source: TBitmap; 
                                startX, StartY: integer); 
var 
  DestDC: HDC; 
  SrcDC:  HDC; 
 
begin 
  DestDC := Destination.Picture.Bitmap.Canvas.Handle; 
  SrcDC  := Source.Canvas.Handle; 
 
  BitBlt(DestDC, x, y, W, H, SrcDC, startX, StartY, SRCCOPY); 
  Destination.Refresh; 
end; 
 
procedure TViewChannelForm.BtnImageLoad(Btn_No : integer; b_Pressed, b_Highlighted : boolean); 
 procedure SetImage2(Dest_No: integer; 
                                x, y, W, H: integer; 
                                Source: TBitmap; 
                                StartX, StartY: integer); 
 begin 
   case Dest_No of 
     1: SetImage(chImageBtn1, x, y, w, h, Source, startX, StartY); 
     2: SetImage(chImageBtn2, x, y, w, h, Source, startX, StartY); 
     3: SetImage(chImageBtn3, x, y, w, h, Source, startX, StartY); 
     4: SetImage(chImageBtn4, x, y, w, h, Source, startX, StartY); 
     5: SetImage(chImageBtn5, x, y, w, h, Source, startX, StartY); 
     6: SetImage(chImageBtn6, x, y, w, h, Source, startX, StartY); 
     7: SetImage(chImageBtn7, x, y, w, h, Source, startX, StartY); 
     8: SetImage(chImageBtn8, x, y, w, h, Source, startX, StartY); 
     9: SetImage(chImageBtn9, x, y, w, h, Source, startX, StartY); 
     10: SetImage(chImageBtn10, x, y, w, h, Source, startX, StartY); 
     11: SetImage(chImageBtn11, x, y, w, h, Source, startX, StartY); 
     12: SetImage(chImageBtn12, x, y, w, h, Source, startX, StartY); 
     13: SetImage(chImageBtn13, x, y, w, h, Source, startX, StartY); 
     14: SetImage(chImageBtn14, x, y, w, h, Source, startX, StartY); 
     15: SetImage(chImageBtn15, x, y, w, h, Source, startX, StartY); 
     16: SetImage(chImageBtn16, x, y, w, h, Source, startX, StartY); 
     41: SetImage(btn_Solo1, x, y, w, h, Source, startX, StartY); 
     42: SetImage(btn_Solo2, x, y, w, h, Source, startX, StartY); 
     43: SetImage(btn_Solo3, x, y, w, h, Source, startX, StartY); 
     44: SetImage(btn_Solo4, x, y, w, h, Source, startX, StartY); 
     45: SetImage(btn_Solo5, x, y, w, h, Source, startX, StartY); 
     46: SetImage(btn_Solo6, x, y, w, h, Source, startX, StartY); 
     47: SetImage(btn_Solo7, x, y, w, h, Source, startX, StartY); 
     48: SetImage(btn_Solo8, x, y, w, h, Source, startX, StartY); 
     49: SetImage(btn_Solo9, x, y, w, h, Source, startX, StartY); 
     50: SetImage(btn_Solo10, x, y, w, h, Source, startX, StartY); 
     51: SetImage(btn_Solo11, x, y, w, h, Source, startX, StartY); 
     52: SetImage(btn_Solo12, x, y, w, h, Source, startX, StartY); 
     53: SetImage(btn_Solo13, x, y, w, h, Source, startX, StartY); 
     54: SetImage(btn_Solo14, x, y, w, h, Source, startX, StartY); 
     55: SetImage(btn_Solo15, x, y, w, h, Source, startX, StartY); 
     56: SetImage(btn_Solo16, x, y, w, h, Source, startX, StartY); 
   end; 
 end; 
 
begin 
  case Btn_No of 
    1..16 : if b_Pressed then 
           begin 
              if ChannelState[Btn_No-1] then 
                 SetImage2(Btn_No, 0, 0, 43, 16, Image_Controls, 0, 51) 
              else 
                 SetImage2(Btn_No, 0, 0, 43, 16, Image_Controls, 0, 17) 
           end else 
              if b_Highlighted then 
              begin 
                if ChannelState[Btn_No-1] then 
                   SetImage2(Btn_No, 0, 0, 43, 16, Image_Controls, 0, 85) 
                else 
                   SetImage2(Btn_No, 0, 0, 43, 16, Image_Controls, 0, 68); 
              end else 
              begin 
                if ChannelState[Btn_No-1] then 
                   SetImage2(Btn_No, 0, 0, 43, 16, Image_Controls, 0, 34) 
                else 
                   SetImage2(Btn_No, 0, 0, 43, 16, Image_Controls, 0, 0); 
              end; 
         
    41..56 : if b_Pressed then 
               SetImage2(Btn_No, 0, 0, 27, 16, Image_Controls, 100, 70) 
             else if b_Highlighted then 
               SetImage2(Btn_No, 0, 0, 27, 16, Image_Controls, 72, 70) 
             else 
               SetImage2(Btn_No, 0, 0, 27, 16, Image_Controls, 44, 70); 
   end; 
end; 
 
procedure TViewChannelForm.chImageBtnMouseLeave(Sender: TObject); 
begin 
  if (Sender as TComponent).Tag = i_CursorOn then 
     i_CursorOn := 0; 
 
 { if b_BtnPressed then 
     b_BtnPressed := false; } 
 
  BtnImageLoad((Sender as TComponent).Tag, false, false); 
 
  if b_BtnPressed then 
     b_BtnPressed := false; 
end; 
 
procedure TViewChannelForm.chImageBtnMouseUp(Sender: TObject; 
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 
begin 
  b_BtnPressed := false; 
  ReleaseCapture; 
  if (Sender as TComponent).Tag = i_CursorOn then 
  begin 
    if ((Sender as TAdvImage).Tag >= 1) and ((Sender as TAdvImage).Tag <= 16) then 
    begin 
      ChannelState[(Sender as TComponent).Tag - 1] := not ChannelState[(Sender as TComponent).Tag - 1]; 
      SetPlayerChannelState; 
    end; 
    BtnImageLoad((Sender as TComponent).Tag, false, true); 
  end else 
    BtnImageLoad((Sender as TComponent).Tag, false, false); 
 
  case (Sender as TComponent).Tag of 
    21..36 : NowTracking := false; 
    41..56 : btnSolo_NClick(Sender); 
  end; 
 
end; 
 
procedure TViewChannelForm.chImageBtnMouseDown(Sender: TObject; 
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 
var 
  CurCursor: HCURSOR; 
  m_point: TPoint; 
begin 
  if not (ssLeft in Shift) then 
      exit; 
 
  b_BtnPressed := true; 
  SetCapture(Self.Handle); 
  BtnImageLoad((Sender as TComponent).Tag, true, false); 
 
   case (Sender as TComponent).Tag of 
     21..36 : begin 
            NowTracking := true; 
            CurCursor := GetCursor; 
            if CurCursor <> CURSOR_HAND then 
              SetCursor(CURSOR_HAND); 
            GetCursorPos(m_point); 
            ThumbStartX := (Sender as TControl).Left; 
            ThumbMouseDownX := m_point.X; 
          end; 
   end; 
 
  if i_CursorOn <>(Sender as TComponent).Tag then   // for the case of no response 
    i_CursorOn :=(Sender as TComponent).Tag; 
end; 
 
procedure TViewChannelForm.chImageBtnMouseEnter(Sender: TObject); 
begin 
  i_CursorOn := (Sender as TComponent).Tag; 
 
  if b_BtnPressed then 
     exit; 
 
  BtnImageLoad((Sender as TComponent).Tag, false, true); 
end; 
 
procedure TViewChannelForm.cbMIDIModeChange(Sender: TObject); 
begin 
  if cbMIDIMode.Text = 'GS' then 
  begin 
    MIDI_Mode := GS; 
    MainForm.MidiPlayer.GM2_OnOff(false); 
  end else if cbMIDIMode.Text = 'GM2' then 
  begin 
    MIDI_Mode := GM2; 
    MainForm.MidiPlayer.GM2_OnOff(true); 
  end; 
 
  ResetFields(false); 
end; 
 
procedure TViewChannelForm.FaderThumbMouseMove(Sender: TObject; 
  Shift: TShiftState; X, Y: Integer); 
var 
   CurCursor : HCURSOR; 
   diffX, NewPosX : integer; 
   m_point : TPoint; 
   ThumbNum : integer; 
   SlideValue: integer; 
begin 
   CurCursor := GetCursor; 
   if CurCursor <> CURSOR_HAND then 
   begin 
      SetCursor(CURSOR_HAND); 
    //  OrgCursor := CurCursor; 
   end; 
 
   if not NowTracking then 
      exit; 
 
   GetCursorPos(m_point); 
   diffX := (m_point.X) - ThumbMouseDownX; 
   if diffX <= 0 then 
   begin 
      if (Sender as TControl).Left > ThumbLeftPos then   // 
      begin 
         NewPosX := ThumbStartX + diffX; 
         if NewPosX < ThumbLeftPos then 
            NewPosX := ThumbLeftPos; 
 
         (Sender as TControl).Left := NewPosX; 
      end; 
   end else 
      if (Sender as TControl).Left < (ThumbLeftPos + ThumbTravel) then 
      begin 
         NewPosX := ThumbStartX + diffX; 
         if NewPosX > (ThumbLeftPos + ThumbTravel) then 
            NewPosX := (ThumbLeftPos + ThumbTravel); 
 
          (Sender as TControl).Left := NewPosX; 
      end; 
 
   ThumbNum := (Sender as TComponent).Tag - 20; 
   SlideValue := round(((Sender as TControl).Left - ThumbLeftPos) / ThumbTravel * 127); 
   MainForm.MidiPlayer.SetChannelFader(ThumbNum - 1, SlideValue, FaderType); 
   SetFaderVal(ThumbNum, SlideValue, true{BySlider}); 
end; 
 
procedure TViewChannelForm.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
  PostMessage(MainForm.Handle, WM_ViewChannelConfig, ViewChannel_Closed, 0); 
end; 
 
procedure TViewChannelForm.FormCreate(Sender: TObject); 
var 
  I: integer; 
begin 
 {$IFDEF MULTI_LANGUAGE} 
  TranslateComponent(self); 
 
 {$ENDIF} 
 
  Image_Controls := TBitmap.Create; 
  Image_Controls.LoadFromResourceName(HInstance, 'BUTTONS'); 
  ChannelState := MainForm.MidiPlayer.ChannelState; 
  SetImageBtn(chImageBtn1); 
  SetImageBtn(chImageBtn2); 
  SetImageBtn(chImageBtn3); 
  SetImageBtn(chImageBtn4); 
  SetImageBtn(chImageBtn5); 
  SetImageBtn(chImageBtn6); 
  SetImageBtn(chImageBtn7); 
  SetImageBtn(chImageBtn8); 
  SetImageBtn(chImageBtn9); 
  SetImageBtn(chImageBtn10); 
  SetImageBtn(chImageBtn11); 
  SetImageBtn(chImageBtn12); 
  SetImageBtn(chImageBtn13); 
  SetImageBtn(chImageBtn14); 
  SetImageBtn(chImageBtn15); 
  SetImageBtn(chImageBtn16); 
  SetImageBtn(btn_Solo1); 
  SetImageBtn(btn_Solo2); 
  SetImageBtn(btn_Solo3); 
  SetImageBtn(btn_Solo4); 
  SetImageBtn(btn_Solo5); 
  SetImageBtn(btn_Solo6); 
  SetImageBtn(btn_Solo7); 
  SetImageBtn(btn_Solo8); 
  SetImageBtn(btn_Solo9); 
  SetImageBtn(btn_Solo10); 
  SetImageBtn(btn_Solo11); 
  SetImageBtn(btn_Solo12); 
  SetImageBtn(btn_Solo13); 
  SetImageBtn(btn_Solo14); 
  SetImageBtn(btn_Solo15); 
  SetImageBtn(btn_Solo16); 
  for I := 1 to 16 do 
    BtnImageLoad(I, false, false); 
  for I := 41 to 56 do 
    BtnImageLoad(I, false, false); 
  CURSOR_HAND := LoadCursor(hInstance, 'HAND_CURSOR'); 
 
end; 
 
procedure TViewChannelForm.FormDestroy(Sender: TObject); 
begin 
  Image_Controls.Free; 
end; 
 
procedure TViewChannelForm.FormShow(Sender: TObject); 
begin 
  PostMessage(MainForm.Handle, WM_ViewChannelConfig, ViewChannel_Shown, 0); 
  if MIDI_Mode = GS then 
    cbMIDIMode.ItemIndex := 1 
  else if MIDI_Mode = GM2 then 
    cbMIDIMode.ItemIndex := 0; 
end; 
 
procedure TViewChannelForm.GetChannelEvent(MidiEvent: TMidiEvent); 
var 
  EventNo: byte; 
  ChannelNo: byte; 
begin 
  EventNo := (MidiEvent.Event and $F0); 
  ChannelNo := (MidiEvent.Event and $0F) + 1; 
  case EventNo of 
    $B0 : if MidiEvent.Data1 = 0 then         // Bank Select coarse 
            BankData[ChannelNo] := MidiEvent.Data2 
          else if MidiEvent.Data1 = 32 then   // Bank Select fine 
            MapData[ChannelNo] := MidiEvent.Data2 
      // 7 : Volume, 10 : Pan, 11 : Expression, 91 : Reverb, 93 : Chorus, 94 : Delay 
          else if (MidiEvent.Data1 = 7) or (MidiEvent.Data1 = 10) or (MidiEvent.Data1 = 11) or 
              (MidiEvent.Data1 = 91) or (MidiEvent.Data1 = 93) or (MidiEvent.Data1 = 94) then 
          begin 
            if (rbVolume.Checked and (MidiEvent.Data1 = 7)) or 
               (rbPan.Checked and (MidiEvent.Data1 = 10)) or 
               (rbExpression.Checked and (MidiEvent.Data1 = 11)) or 
               (rbReverb.Checked and (MidiEvent.Data1 = 91)) or 
               (rbChorus.Checked and (MidiEvent.Data1 = 93)) or 
               (rbDelay.Checked and (MidiEvent.Data1 = 94)) then 
              SetFaderVal(ChannelNo, MidiEvent.Data2, false) 
            else 
              case MidiEvent.Data1 of 
                 7 : VolumeData[ChannelNo] := MidiEvent.Data2; 
                10 : PanData[ChannelNo] := MidiEvent.Data2; 
                11 : ExpressionData[ChannelNo] := MidiEvent.Data2; 
                91 : ReverbData[ChannelNo] := MidiEvent.Data2; 
                93 : ChorusData[ChannelNo] := MidiEvent.Data2; 
                94 : DelayData[ChannelNo] := MidiEvent.Data2; 
              end; 
          end; 
    $C0 : if MIDI_Mode = GS then 
            SetInstrumentName(MIDI_Mode, ChannelNo, BankData[ChannelNo], MidiEvent.Data1) 
          else if MIDI_Mode = GM2 then 
            if (BankData[ChannelNo] = 120) and (MapData[ChannelNo] = 0) then  // It's a drum kit ? 
            begin 
              case ChannelNo of 
                 1 : lblInst1.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 2 : lblInst2.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 3 : lblInst3.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 4 : lblInst4.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 5 : lblInst5.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 6 : lblInst6.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 7 : lblInst7.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 8 : lblInst8.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                 9 : lblInst9.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                10 : lblInst10.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                11 : lblInst11.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                12 : lblInst12.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                13 : lblInst13.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                14 : lblInst14.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                15 : lblInst15.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
                16 : lblInst16.Caption := GetDrumKitName(MidiEvent.Data1 + 1); 
              end; 
            end else {if (BankData[ChannelNo] = 121) then } 
              SetInstrumentName(MIDI_Mode, ChannelNo, MapData[ChannelNo], MidiEvent.Data1) 
           { else 
              SetInstrumentName(MIDI_Mode, ChannelNo, BankData[ChannelNo], MidiEvent.Data1)}; 
 
  end; 
  if (EventNo >= $80) and (EventNo <= $E0) then 
    case ChannelNo of 
      1 : Led_CH1.Blink(OnInterval); 
      2 : Led_CH2.Blink(OnInterval); 
      3 : Led_CH3.Blink(OnInterval); 
      4 : Led_CH4.Blink(OnInterval); 
      5 : Led_CH5.Blink(OnInterval); 
      6 : Led_CH6.Blink(OnInterval); 
      7 : Led_CH7.Blink(OnInterval); 
      8 : Led_CH8.Blink(OnInterval); 
      9 : Led_CH9.Blink(OnInterval); 
      10 : Led_CH10.Blink(OnInterval); 
      11 : Led_CH11.Blink(OnInterval); 
      12 : Led_CH12.Blink(OnInterval); 
      13 : Led_CH13.Blink(OnInterval); 
      14 : Led_CH14.Blink(OnInterval); 
      15 : Led_CH15.Blink(OnInterval); 
      16 : Led_CH16.Blink(OnInterval); 
    end; 
end; 
 
procedure TViewChannelForm.rbFaderSelClick(Sender: TObject); 
var 
  I: integer; 
  FaderData: array[1..16] of byte; 
begin 
  if rbVolume.Checked then begin 
    FaderType := fVolume; 
    for I := 1 to 16 do 
      FaderData[I] := VolumeData[I]; 
  end else if rbPan.Checked then begin 
    FaderType := fPan; 
    for I := 1 to 16 do 
      FaderData[I] := PanData[I]; 
  end else if rbExpression.Checked then begin 
    FaderType := fExpression; 
    for I := 1 to 16 do 
      FaderData[I] := ExpressionData[I]; 
  end else if rbReverb.Checked then begin 
    FaderType := fReverb; 
    for I := 1 to 16 do 
      FaderData[I] := ReverbData[I]; 
  end else if rbChorus.Checked then begin 
    FaderType := fChorus; 
    for I := 1 to 16 do 
      FaderData[I] := ChorusData[I]; 
  end else if rbDelay.Checked then begin 
    FaderType := fDelay; 
    for I := 1 to 16 do 
      FaderData[I] := DelayData[I]; 
  end; 
 
  for I := 1 to 16 do 
    SetSlidePos(I, FaderData[I]); 
 
  lblFader1.Caption := intToStr(FaderData[1]); 
  lblFader2.Caption := intToStr(FaderData[2]); 
  lblFader3.Caption := intToStr(FaderData[3]); 
  lblFader4.Caption := intToStr(FaderData[4]); 
  lblFader5.Caption := intToStr(FaderData[5]); 
  lblFader6.Caption := intToStr(FaderData[6]); 
  lblFader7.Caption := intToStr(FaderData[7]); 
  lblFader8.Caption := intToStr(FaderData[8]); 
  lblFader9.Caption := intToStr(FaderData[9]); 
  lblFader10.Caption := intToStr(FaderData[10]); 
  lblFader11.Caption := intToStr(FaderData[11]); 
  lblFader12.Caption := intToStr(FaderData[12]); 
  lblFader13.Caption := intToStr(FaderData[13]); 
  lblFader14.Caption := intToStr(FaderData[14]); 
  lblFader15.Caption := intToStr(FaderData[15]); 
  lblFader16.Caption := intToStr(FaderData[16]); 
end; 
 
end.