⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmmixctl.pas

📁 一套及时通讯的原码
💻 PAS
📖 第 1 页 / 共 5 页
字号:

   if FLink.Control <> Value then
   begin
      FLink.Control:= Value;
      if Value <> nil then
         Value.FreeNotification(Self);
      UpdateControl;
   end;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.SetItemLine(Value: TMMAudioLine);
begin
    if FItemLine <> Value then
    begin
        if FItemLine <> nil then
            FItemLine.RemoveObserver(FItemObserver);
        FItemLine := Value;
        if FItemLine <> nil then
        begin
            FItemLine.AddObserver(FItemObserver);
            FItemLine.FreeNotification(Self);
        end;
        UpdateControl;
    end;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.ItemNotify(Sender, Data: TObject);
begin
    if (Data = nil) or (Data is TMMLineIdChange) then
        UpdateControl;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
function  TMMCustomMixerCheckBox.StoreItem: Boolean;
begin
    Result := (FItemLine = nil) and (FItem <> NoItem);
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.SetAutoCap(Value: Boolean);
begin
   if Value <> FAutoCap then
   begin
      FAutoCap:= Value;
      UpdateControl;
   end;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.SetShort(Value: Boolean);
begin
   if Value <> FShort then
   begin
      FShort:= Value;
      UpdateControl;
   end;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
function TMMCustomMixerCheckBox.StoreCaption: Boolean;
begin
   Result:= not AutoCaption;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.ControlChange(Sender: TObject);
begin
   UpdateControl;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.SetupCheck;
begin
   if Control <> nil then
   begin
      if (Control <> nil) and (FItemLine <> nil) then
        FItem := Control.GetItemForLine(FItemLine);

      inherited Enabled:= FEnabled and WriteOk(Control,FItem);

      if inherited Enabled and AutoCaption then
         if FItem <> NoItem then
            Caption := Control.ItemInfo[FItem].Name
         else if Short then
            Caption := Control.ControlInfo.ShortName
         else
            Caption := Control.ControlInfo.Name
   end
   else inherited Enabled := False;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.UpdateValue;
begin
   if ReadOk(Control,FItem) then
   begin
      FLink.Lock;
      try
         Checked:= Control.GetChannelBoolean(FChannel,FItem);
      finally
         FLink.Unlock;
      end;
   end;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.Loaded;
begin
   inherited Loaded;

   UpdateControl;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.Notification(AComponent: TComponent; Operation: TOperation);
begin
   inherited Notification(AComponent,Operation);

   if Operation = opRemove then
      if AComponent = Control then
         Control:= nil;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.Click;
begin
   if not FLink.Locked then
   begin
      FLink.Lock;
      try
         if inherited Enabled then
            Control.SetChannelBoolean(FChannel,FItem,Checked)
         else
            UpdateControl;
      finally
         FLink.Unlock;
      end;
   end;
   inherited;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.UpdateControl;
begin
   SetupCheck;
   UpdateValue;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.SetChannel(Value: TMMChannel);
begin
   if FChannel <> Value then
   begin
      FChannel:= Value;
      UpdateControl;
   end;
end;

{-- TMMCustomMixerCheckBox ---------------------------------------------}
procedure TMMCustomMixerCheckBox.SetItem(Value: TMMItemIndex);
begin
   if FItem <> Value then
   begin
      FItem:= Value;
      UpdateControl;
   end;
end;

{== TMMCustomMixerConnector ============================================}
constructor TMMCustomMixerConnector.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);

   FAbsolute       := True;
   FLink           := TMMControlLink.Create;
   FLink.OnChange  := ControlChange;
   FLink.OnIdChange:= UpdateControl;
   FItem           := NoItem;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
destructor TMMCustomMixerConnector.Destroy;
begin
    FLink.Free;

    inherited Destroy;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
function TMMCustomMixerConnector.GetControl: TMMCustomMixerControl;
begin
   Result := FLink.Control;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.SetControl(Value: TMMCustomMixerControl);
begin
   if Value <> nil then
      if not (Value.ControlClass in ConnectorControlClasses) then
         { TODO: Should be resource id }
         raise EMMMixerControlsError.Create('Invalid control class');

   if FLink.Control <> Value then
   begin
      FLink.Control:= Value;
      if Value <> nil then
         Value.FreeNotification(Self);
      UpdateControl;
   end;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.ControlChange(Sender: TObject);
begin
   UpdateControl;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.SetupConnector;

    function Enable(Value: Boolean): Boolean;
    begin
       if assigned(Meter1) then TMMMeter(Meter1).Enabled := Value;
       if assigned(Meter2) then TMMMeter(Meter2).Enabled := Value;
       if assigned(Level1) then TMMLevel(Level1).Enabled := Value;
       if assigned(Level2) then TMMLevel(Level2).Enabled := Value;
       Result:= Value;
    end;
var
    MaxVal: Integer;
begin
   FStep:= 0;
   if Control = nil then Enable(False)
   else
   begin
      if Enable(Enabled and ReadOk(Control,FItem)) then
      with Control.ControlInfo do
      begin
         FAbsolute := True;
         if Control.ValidMixer then
            if (Control.Mixer.DeviceCaps.ManufacturerID = MM_ANTEX) then
                FAbsolute := False;

         if FAbsolute then
            MaxVal := Max(Abs(MinValue),Abs(MaxValue))
         else
         begin
            MaxVal := MaxValue-MinValue;

            if (MinValue < 0) then
                FAdjust := -MinValue
            else
                FAdjust := 0;
         end;

         if MaxVal <> 0 then
            FStep  := 32768 / MaxVal
         else
            FStep  := 0;

         {$IFDEF _MMDEBUG}
         DB_WriteStrLn(0,'MinValue: '+IntToStr(MinValue));
         DB_WriteStrLn(0,'MaxValue: '+IntToStr(MaxValue));
         DB_WriteStrLn(0,'Step: '+FloatToStr(FStep));
         DB_WriteStrLn(0,'HasMixer: '+IntToStr(Ord(Control.ValidMixer)));
         {$ENDIF}
      end;
   end;

   inherited;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.Notification(AComponent: TComponent; Operation: TOperation);
begin
   inherited Notification(AComponent,Operation);

   if Operation = opRemove then
      if AComponent = Control then
         Control := nil;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.SetItem(Value: TMMItemIndex);
begin
   if FItem <> Value then
   begin
      FItem:= Value;
      UpdateControl;
   end;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.GetLevelValues(var LeftValue, RightValue, BothValue: integer);
var
   Curr: TMMCurrentValue;

begin
   LeftValue  := 0;
   RightValue := 0;
   BothValue  := 0;

   if not (csLoading in ComponentState) and
      not (csReading in ComponentState) and
           ReadOk(Control,FItem) then
   begin
      Curr[chLeft]  := Control.GetChannelSigned(chLeft,FItem);
      Curr[chRight] := Control.GetChannelSigned(chRight,FItem);
      Curr[chBoth]  := Control.GetChannelSigned(chBoth,FItem);

      if FStep <> 0 then
      begin
         {$IFDEF _MMDEBUG}
         DB_WriteStrLn(0,'Left Value: '+IntToStr(Curr[chLeft]));
         DB_WriteStrLn(0,'Right Value: '+IntToStr(Curr[chRight]));
         DB_WriteStrLn(0,'Both Value: '+IntToStr(Curr[chBoth]));
         {$ENDIF}

         if FAbsolute then
         begin
            LeftValue := Round(Abs(Curr[chLeft]) * FStep);
            RightValue:= Round(Abs(Curr[chRight]) * FStep);
            BothValue := Round(Abs(Curr[chBoth]) * FStep);
         end
         else
         begin
            LeftValue := Round((Curr[chLeft]+FAdjust) * FStep);
            RightValue:= Round((Curr[chRight]+FAdjust) * FStep);
            BothValue := Round((Curr[chBoth]+FAdjust) * FStep);
         end;

         {$IFDEF _MMDEBUG}
         DB_WriteStrLn(0,'Left Level: '+IntToStr(LeftValue));
         DB_WriteStrLn(0,'Right Level: '+IntToStr(RightValue));
         DB_WriteStrLn(0,'Both Level: '+IntToStr(BothValue));
         {$ENDIF}
      end;

      if not FPrevValid or not GlobalCmpMem(Curr, FPrev, SizeOf(Curr)) then
         Changed;

      FPrev       := Curr;
      FPrevValid  := True;
   end;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.Changed;
begin
   DoChange;
end;

{-- TMMCustomMixerConnector --------------------------------------------}
procedure TMMCustomMixerConnector.DoChange;
begin
   if Assigned(FOnChange) then
      FOnChange(Self);
end;

{== TMMMixerLabelConnector =============================================}
constructor TMMMixerLabelConnector.Create(AOwner: TComponent);
begin
   inherited   Create(AOwner);

   FCaptionLink          := TMMCaptionLink.Create;
   FCaptionLink.OnChange := CaptionChanged;
end;

{-- TMMMixerLabelConnector ---------------------------------------------}
destructor TMMMixerLabelConnector.Destroy;
begin
   FCaptionLink.Free;

   inherited Destroy;
end;

{-- TMMMixerLabelConnector ---------------------------------------------}
procedure TMMMixerLabelConnector.CaptionChanged(Sender: TObject);
begin
   UpdateLabel;
end;

{-- TMMMixerLabelConnector ---------------------------------------------}
procedure TMMMixerLabelConnector.SetSource(Value: TMMCaptionLinkComponent);
begin
   if FCaptionLink.Component <> Value then
   begin
      FCaptionLink.Component:= Value;
      if Value <> nil then
         Value.FreeNotification(Self);
      UpdateLabel;
   end;
end;

{-- TMMMixerLabelConnector ---------------------------------------------}
function TMMMixerLabelConnector.GetSource: TMMCaptionLinkComponent;
begin
   Result := FCaptionLink.Component;
end;

{-- TMMMixerLabelConnector ---------------------------------------------}
procedure TMMMixerLabelConnector.SetItem(Value: TMMItemIndex);
begin
   if FCaptionLink.Item <> Value then
   begin
      FCaptionLink.Item := Value;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -