📄 u_crc_main.pas
字号:
(*
----------------------------------------------
u_crc_main.pas - ConfRoomClient / main form
Voice Communicator components version 2.5
----------------------------------------------
This source code cannot be used without
proper license granted to you as a private
person or an entity by the Lake of Soft, Ltd
Visit http://lakeofsoft.com/ for more information.
Copyright (c) 2001, 2007 Lake of Soft, Ltd
All rights reserved
----------------------------------------------
created by:
Lake, 08 Jul 2003
modified by:
Lake, Jul-Dec 2003
Lake, Jan-Jul 2004
Lake, May-Oct 2005
Lake, Apr 2007
----------------------------------------------
*)
{$I unaDef.inc }
unit
u_crc_main;
interface
uses
Windows, Messages, unaTypes, unaUtils, unaClasses, unaSockets, unaConfClient, unaVcIde, unaDspControls,
Forms, Classes, ActnList, ExtCtrls, StdCtrls, Controls, ComCtrls, CheckLst, Menus, Dialogs;
type
//
// -- --
//
Tc_crcForm_main = class(TForm)
c_edit_srvAddr: TEdit;
Label1: TLabel;
c_edit_srvPort: TEdit;
Label2: TLabel;
Label3: TLabel;
c_comboBox_connType: TComboBox;
c_button_connect: TButton;
c_button_disconnect: TButton;
c_button_send: TButton;
c_actionList_main: TActionList;
a_cln_connect: TAction;
a_cln_disconnect: TAction;
c_timer_update: TTimer;
c_statusBar_main: TStatusBar;
a_cln_send: TAction;
c_clb_debug: TCheckListBox;
c_bevel_middle: TBevel;
c_fontDialog_chat: TFontDialog;
c_button_chooseFont: TButton;
c_re_chat: TRichEdit;
c_re_userText: TRichEdit;
c_pm_chat: TPopupMenu;
Clear1: TMenuItem;
c_label_nn: TLabel;
c_edit_nickname: TEdit;
Label4: TLabel;
c_comboBox_sd: TComboBox;
c_progressBar_volumeIn: TProgressBar;
c_progressBar_volumeOut: TProgressBar;
c_checkBox_rec: TCheckBox;
c_checkBox_play: TCheckBox;
c_button_clickTT: TButton;
Label5: TLabel;
c_button_audioSetup: TButton;
a_cln_audioSetup: TAction;
c_mainMenu_app: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
N1: TMenuItem;
Connect1: TMenuItem;
Disconect1: TMenuItem;
Edit1: TMenuItem;
Send1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
Bevel1: TBevel;
c_band_in: TunadspFFTControl;
c_band_out: TunadspFFTControl;
//
procedure formCreate(sender: tObject);
procedure formDestroy(sender: tObject);
procedure formShow(sender: tObject);
procedure formClose(sender: tObject; var action: tCloseAction);
//
procedure c_timer_updateTimer(Sender: TObject);
//
procedure a_cln_connectExecute(Sender: TObject);
procedure a_cln_disconnectExecute(Sender: TObject);
procedure a_cln_sendExecute(Sender: TObject);
procedure a_cln_audioSetupExecute(Sender: TObject);
//
procedure c_comboBox_sdChange(Sender: TObject);
//
procedure clear1Click(Sender: TObject);
//
procedure c_checkBox_recClick(Sender: TObject);
procedure c_checkBox_playClick(Sender: TObject);
//
procedure c_button_clickTTClick(Sender: TObject);
procedure c_button_chooseFontClick(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
private
{ private declarations }
f_config: unaIniFile;
f_client: unaConfClientClass;
f_selfDisconnect: bool;
f_log: unaStringList;
//
f_timerUpdate: bool;
//
f_wides: array[byte] of wideString;
f_wideCount: unsigned;
f_wideGate: unaInProcessGate;
//
f_cct_enabled: bool;
f_cct_hotkey: int;
f_cct_mode: int;
//
procedure gotText(connId: unsigned; data: pointer; len: unsigned);
procedure addToLog(const text: string);
procedure addWides();
//
procedure checkCTT(updateParams: bool = true);
//
function getREwideText(re: TRichEdit): wideString;
function setREwideText(re: TRichEdit; const text: wideString): LRESULT;
//
procedure minMaxInfo(var message: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
//
procedure onClientSE(sender: tObject; connectionId: unsigned; event: unaSocketEvent; data: pointer; len: unsigned);
procedure onClientPE(sender: tObject; connectionId: unsigned; const packet: unavclInOutIPPacket);
public
{ public declarations }
end;
var
c_crcForm_main: Tc_crcForm_main;
implementation
{$R *.dfm}
uses
sysUtils, unaVCLUtils, unaMsAcmAPI, unaMsAcmClasses,
RichEdit, u_crc_clickToTalk, u_common_audioConfig;
// -- --
procedure Tc_crcForm_main.formCreate(sender: tObject);
begin
f_config := unaIniFile.create();
f_client := unaConfClientClass.create();
f_client.onSocketEvent := onClientSE;
f_client.onPacketEvent := onClientPE;
//
f_wideGate := unaInProcessGate.create();
//
f_client.setConfig(8000, 16, 1, 49{GSM});
f_log := unaStringList.create();
//
f_client.waveIn.addConsumer(c_band_in.fft);
f_client.codecOut.addConsumer(c_band_out.fft);
end;
// -- --
procedure Tc_crcForm_main.FormDestroy(sender: tObject);
begin
freeAndNil(f_wideGate);
freeAndNil(f_log);
freeAndNil(f_config);
freeAndNil(f_client);
end;
// -- --
procedure Tc_crcForm_main.formShow(sender: tObject);
begin
loadControlPosition(self, f_config);
//
c_edit_srvAddr.text := f_config.get('ip.srv.addr', '192.168.1.1');
c_edit_srvPort.text := f_config.get('ip.srv.port', '17900');
c_edit_nickname.text := f_config.get('gui.nickname', 'Lake');
//
c_comboBox_connType.itemIndex := f_config.get('ip.connType', int(0));
c_comboBox_sd.itemIndex := f_config.get('wave.sd.index', int(4));
//
c_comboBox_sdChange(sender);
//
{$IFDEF DEBUG }
{$ELSE }
About1Click(self);
{$ENDIF }
//
c_timer_update.enabled := true;
//
// limit formats to conform with server's default 8000 Hz/mono stream
c_form_common_audioConfig.enumFormat.nSamplesPerSec := 8000;
c_form_common_audioConfig.enumFormat.nChannels := 1;
c_form_common_audioConfig.setupUI(true, true, false);
//
c_form_common_audioConfig.doLoadConfig(f_client.waveIn, f_client.waveOut, f_client.codecIn, nil, f_config);
end;
// -- --
procedure Tc_crcForm_main.formClose(sender: tObject; var action: tCloseAction);
begin
c_timer_update.enabled := false;
//
a_cln_disconnect.execute();
//
with (f_config) do begin
//
setValue('ip.srv.addr', c_edit_srvAddr.text);
setValue('ip.srv.port', c_edit_srvPort.text);
setValue('ip.connType', c_comboBox_connType.itemIndex);
setValue('gui.nickname', c_edit_nickname.text);
setValue('wave.sd.index', c_comboBox_sd.itemIndex);
end;
//
saveControlPosition(self, f_config);
end;
const
//* Flags for the SETEXTEX data structure */
ST_DEFAULT = 0;
ST_KEEPUNDO = 1;
ST_SELECTION = 2;
EM_SETTEXTEX = WM_USER + 97;
type
SETTEXTEX = packed record
flags: DWORD;
codepage: UINT;
end;
// -- --
procedure Tc_crcForm_main.c_timer_updateTimer(Sender: TObject);
var
minVL, minAT: int;
device: unaMsAcmStreamDevice;
s: string;
begin
f_timerUpdate := true;
//
c_statusBar_main.panels[0].text := 'Mem: ' + int2str(ams() shr 10, 10, 3) + ' KB';
c_statusBar_main.panels[2].text := 'Received/Sent: ' + int2str(f_client.ipClient.inPacketsCount, 10, 3) + ' / ' + int2str(f_client.ipClient.outPacketsCount, 10, 3) + ' packets.';
//
{$IFDEF DEBUG}
c_clb_debug.checked[0] := f_client.waveIn.active;
c_clb_debug.checked[1] := f_client.codecIn.active;
c_clb_debug.checked[2] := f_client.ipClient.active;
c_clb_debug.checked[3] := f_client.codecOut.active;
c_clb_debug.checked[4] := f_client.waveOut.active;
//
if (0 <= c_clb_debug.itemIndex) then begin
//
case (c_clb_debug.itemIndex) of
0: device := f_client.waveIn.device;
1: device := f_client.codecIn.device;
2: device := nil;
3: device := f_client.codecOut.device;
4: device := f_client.waveOut.device;
else
device := nil;
end;
//
if (nil <> device) then
s := device.srcFormatInfo + ' -> ' + device.dstFormatInfo + ' | in/out: ' + int2str(device.inBytes) + '/' + int2str(device.outBytes)
else
s := '';
//
label5.caption := s;
end;
//
label5.visible := true;
c_clb_debug.visible := true;
{$ELSE}
label5.visible := false;
c_clb_debug.visible := false;
{$ENDIF}
//
c_progressBar_volumeIn.position := f_client.getVolume(true);
c_progressBar_volumeOut.position := f_client.getVolume(false);
//
if (0 < f_log.count) then begin
//
c_re_chat.lines.add(f_log.get(0));
f_log.removeByIndex(0);
end;
//
if ((0 < f_wideCount) and f_wideGate.enter(10)) then
try
addWides();
finally
f_wideGate.leave();
end;
//
c_checkBox_rec.enabled := f_client.ipClient.active;
c_checkBox_play.enabled := f_client.ipClient.active;
//
f_client.getSilenceDetectionParams(minVL, minAT);
//
if (c_checkBox_rec.enabled) then
c_checkBox_rec.checked := f_client.recordingEnabled
else
c_checkBox_rec.checked := false;
//
if (c_checkBox_play.enabled) then
c_checkBox_play.checked := f_client.playbackEnabled
else
c_checkBox_play.checked := false;
//
checkCTT(false);
//
f_timerUpdate := false;
end;
// -- --
procedure Tc_crcForm_main.a_cln_connectExecute(Sender: TObject);
var
connType: tunavclProtoType;
begin
// connect client
case (c_comboBox_connType.itemIndex) of
//
0:
connType := unapt_UDP;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -