From: Bellai Ádám Date: Tue, 14 Nov 2017 14:16:12 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=ef3e163e28b658dce4e1a5308ba74952b698ae81;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30726 --- diff --git a/client/AudioRecorder/CustomTrackBar.cs b/client/AudioRecorder/CustomTrackBar.cs index 97c101a3..0a997d85 100644 --- a/client/AudioRecorder/CustomTrackBar.cs +++ b/client/AudioRecorder/CustomTrackBar.cs @@ -1,40 +1,43 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Drawing; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -namespace AudioRecorder -{ - public partial class CustomTrackBar : UserControl - { +namespace AudioRecorder { + public partial class CustomTrackBar : UserControl { + public delegate void SetValueDelegate(int value); + public MainForm MainForm { get; set; } - public CustomTrackBar() - { + private SetValueDelegate setValueDelegate; + + public CustomTrackBar() { InitializeComponent(); } - public void setMinimumMaximumSizesAndVolume(int minimum, int maximum, int value) - { + public void setMinimumMaximumSizesAndVolume(int minimum, int maximum, int value) { trackBar1.Maximum = maximum; trackBar1.Minimum = minimum; trackBar1.Value = value; } - public void setTickLabelLocationByPercentage(int percentage) - { + public void setTickLabelLocationByPercentage(int percentage) { //mert a magasága a trackbarnak 200 tickLabel.Location = new Point(tickLabel.Location.X, 200 - (percentage * 2)); } - private void trackBar1_ValueChanged(object sender, EventArgs e) - { + private void trackBar1_ValueChanged(object sender, EventArgs e) { MainForm.volumeChanged(sender, e); } + + public void SetValue(int value) { + if (trackBar1.InvokeRequired) { + setValueDelegate = SetTrackBarValue; + this.Invoke(setValueDelegate, new Object[] { value }); + } else SetTrackBarValue(value); + } + + private void SetTrackBarValue(int value) { + trackBar1.Value = value; + } } } diff --git a/client/AudioRecorder/MainForm.Designer.cs b/client/AudioRecorder/MainForm.Designer.cs index ea1c0188..784534c0 100644 --- a/client/AudioRecorder/MainForm.Designer.cs +++ b/client/AudioRecorder/MainForm.Designer.cs @@ -34,11 +34,11 @@ namespace AudioRecorder { this.groupBox4 = new System.Windows.Forms.GroupBox(); this.pauseButton = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.verticalProgressBar1 = new AudioRecorder.VerticalProgressBar(); this.customTrackBar1 = new AudioRecorder.CustomTrackBar(); this.fileNameLabel = new System.Windows.Forms.Label(); this.playButton = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); - this.verticalProgressBar1 = new AudioRecorder.VerticalProgressBar(); this.groupBox1.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -147,6 +147,15 @@ namespace AudioRecorder { this.groupBox2.TabIndex = 6; this.groupBox2.TabStop = false; // + // verticalProgressBar1 + // + this.verticalProgressBar1.BackColor = System.Drawing.Color.White; + this.verticalProgressBar1.ForeColor = System.Drawing.Color.White; + this.verticalProgressBar1.Location = new System.Drawing.Point(18, 19); + this.verticalProgressBar1.Name = "verticalProgressBar1"; + this.verticalProgressBar1.Size = new System.Drawing.Size(15, 203); + this.verticalProgressBar1.TabIndex = 12; + // // customTrackBar1 // this.customTrackBar1.Location = new System.Drawing.Point(39, 15); @@ -189,15 +198,6 @@ namespace AudioRecorder { this.groupBox3.TabIndex = 10; this.groupBox3.TabStop = false; // - // verticalProgressBar1 - // - this.verticalProgressBar1.BackColor = System.Drawing.Color.White; - this.verticalProgressBar1.ForeColor = System.Drawing.Color.White; - this.verticalProgressBar1.Location = new System.Drawing.Point(18, 19); - this.verticalProgressBar1.Name = "verticalProgressBar1"; - this.verticalProgressBar1.Size = new System.Drawing.Size(15, 203); - this.verticalProgressBar1.TabIndex = 12; - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/client/AudioRecorder/MainForm.cs b/client/AudioRecorder/MainForm.cs index 6a4ad3ef..25c3423f 100644 --- a/client/AudioRecorder/MainForm.cs +++ b/client/AudioRecorder/MainForm.cs @@ -6,12 +6,12 @@ using NAudio.CoreAudioApi; using System.Windows.Forms; using System.IO; using System.Runtime.InteropServices; -namespace AudioRecorder -{ +using System.Threading; + +namespace AudioRecorder { public delegate void RefreshPanelDelegate(); - public partial class MainForm : Form, IMainForm - { + public partial class MainForm : Form, IMainForm { [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); @@ -28,40 +28,52 @@ namespace AudioRecorder private String currentFileName; private String currentFilePath; private bool recording; - private Timer countDownTimer; + private System.Windows.Forms.Timer countDownTimer; private int countDown = 3; - private Point startingPanelLocation; - private Point originalPanelLocation; private MMDevice currentDevice; private bool pausing; private float volumeHeight; private RefreshPanelDelegate refreshPanel; - public MainForm() - { + public MainForm() { InitializeComponent(); InitializeControlTexts(); customTrackBar1.MainForm = this; - try - { + try { settings = JsonSettings.GetInstance(CONFIG_FILE); fileWorker = new FileWorker(); - countDownTimer = new Timer(); + countDownTimer = new System.Windows.Forms.Timer(); countDownTimer.Interval = 1000; countDownTimer.Tick += new EventHandler(timer_Tick); selectorForm = new AudioDeviceSelectorForm(this); if (selectorForm.isDeviceConnected()) saveAudioDeviceToConfig(); timeCodeWorker = new TimeCodeWorker(timecodeLabel); + CreatenewThreadToListenMasterPeekVolume(); } - catch (Exception e) - { + catch (Exception e) { MessageBox.Show(e.Message, StringResources.ERROR_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void InitializeControlTexts() - { + private void CreatenewThreadToListenMasterPeekVolume() { + new Thread(() => { + while (true) { + try { + int panelHeight = (int)Math.Round(currentDevice.AudioMeterInformation.MasterPeakValue * 100); + Debug.WriteLine(String.Format("panelHeight {0}", panelHeight)); + // int panelHeight = (int)Math.Floor(currentDevice.AudioMeterInformation.MasterPeakValue * 79); + setPanelSizeHeight(panelHeight); + Thread.Sleep(1); + } + catch (Exception e) { + Console.WriteLine(e.Message); + } + } + }).Start(); + } + + private void InitializeControlTexts() { recordButton.Text = Resources.FELVETEL; stopButton.Text = Resources.LEALLITAS; pauseButton.Text = Resources.SZUNET; @@ -69,22 +81,18 @@ namespace AudioRecorder playButton.Text = Resources.LEJATSZAS; } - private void setVolumeTrackerEdgesAndValue() - { - if (currentDevice != null) - { + private void setVolumeTrackerEdgesAndValue() { + if (currentDevice != null) { customTrackBar1.setMinimumMaximumSizesAndVolume((int)currentDevice.AudioEndpointVolume.VolumeRange.MinDecibels, (int)currentDevice.AudioEndpointVolume.VolumeRange.MaxDecibels, (int)currentDevice.AudioEndpointVolume.MasterVolumeLevel); } } - private void saveAudioDeviceToConfig() - { + private void saveAudioDeviceToConfig() { if (String.IsNullOrEmpty(settings.getAudioDeviceName())) recordButton.Enabled = false; - else - { + else { List devices = selectorForm.getDeviceNames(); int indexOfDeviceName = devices.IndexOf(settings.getAudioDeviceName()); if (indexOfDeviceName == -1) @@ -94,11 +102,11 @@ namespace AudioRecorder } } - public void initWavRecorder(int index, String selectedAudioName) - { + public void initWavRecorder(int index, String selectedAudioName) { int inputDeviceIndex = index; this.selectedAudioName = selectedAudioName; currentDevice = selectorForm.getDevices()[index]; + currentDevice.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification; recorder = new WavRecorder(inputDeviceIndex, currentDevice, this); recordButton.Enabled = true; recordButton.BackColor = Color.Lime; @@ -108,39 +116,43 @@ namespace AudioRecorder customTrackBar1.setTickLabelLocationByPercentage(settings.getLoudValue()); } - public void setPanelSizeHeight(float height) - { - volumeHeight = height; - if (verticalProgressBar1.InvokeRequired) { - refreshPanel = RefreshVolumePanel; - this.Invoke(refreshPanel); - } else { - RefreshVolumePanel(); - } + void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data) { + customTrackBar1.SetValue((int)currentDevice.AudioEndpointVolume.MasterVolumeLevel); + } + + public void setPanelSizeHeight(float height) { + volumeHeight = height; + if (verticalProgressBar1.InvokeRequired) { + refreshPanel = RefreshVolumePanel; + this.Invoke(refreshPanel); + } else + RefreshVolumePanel(); } private void RefreshVolumePanel() { - if(volumeHeight > settings.getLoudValue()) - SendMessage(verticalProgressBar1.Handle, 1040, 2, 0); - else - SendMessage(verticalProgressBar1.Handle, 1040, 1, 0); - verticalProgressBar1.Value = (int)volumeHeight; + try { + if (recording) { + if (volumeHeight >= settings.getLoudValue()) + SendMessage(verticalProgressBar1.Handle, 1040, 2, 0); + else + SendMessage(verticalProgressBar1.Handle, 1040, 1, 0); + verticalProgressBar1.Value = (int)volumeHeight; + } + } catch (Exception e) { + Console.WriteLine(e.Message); + } } - private void Form1_Load(object sender, EventArgs e) - { + private void Form1_Load(object sender, EventArgs e) { } - private void stop_Click(object sender, EventArgs e) - { + private void stop_Click(object sender, EventArgs e) { stopRecording(); } - private void stopRecording() - { - try - { + private void stopRecording() { + try { recording = false; recordButton.Enabled = true; stopButton.Enabled = false; @@ -154,47 +166,40 @@ namespace AudioRecorder recordButton.BackColor = Color.Lime; copyFileToUncPath(); } - catch (Exception e) - { + catch (Exception e) { MessageBox.Show(e.Message, StringResources.ERROR_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void copyFileToUncPath() - { + private void copyFileToUncPath() { FileInfo fileInfo = new FileInfo(recorder.getCurentWavFilePath()); String wavFileName = fileInfo.Name; String wavUncPath = DetermineWorkingDirectory(settings.getUncPath(), fileInfo.Name); if (!Directory.Exists(wavUncPath)) Directory.CreateDirectory(wavUncPath); wavUncPath = Path.Combine(wavUncPath, fileInfo.Name); - //String.Format("{0}{1}{2}", settings.getUncPath(), Path.DirectorySeparatorChar, wavFileName); + //String.Format("{0}{1}{2}", settings.getUncPath(), Path.DirectorySeparatorChar, wavFileName); fileWorker.copy(recorder.getCurentWavFilePath(), wavUncPath); } protected String DetermineWorkingDirectory(string path, string ID) { string result = path; string subDir = ID; - if (ID.Contains("_")) { + if (ID.Contains("_")) subDir = ID.Split('_')[0]; - } - if (ID.Contains(".")) { + if (ID.Contains(".")) subDir = ID.Split('.')[0]; - } result = Path.Combine(path, subDir); return result; } - private void record_Click(object sender, EventArgs e) - { + private void record_Click(object sender, EventArgs e) { FileNameForm nameForm = new FileNameForm(this, settings); nameForm.ShowDialog(); } - private void startRecord() - { - try - { + private void startRecord() { + try { recording = true; recorder.StartRecording(currentFilePath); timeCodeWorker.Start(); @@ -206,14 +211,12 @@ namespace AudioRecorder stopButton.BackColor = Color.Red; recordButton.BackColor = Color.White; } - catch (Exception e) - { + catch (Exception e) { MessageBox.Show(e.Message, StringResources.ERROR_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } - public void recordFireEvent(String currentFileName, string id) - { + public void recordFireEvent(String currentFileName, string id) { recordButton.Enabled = false; String path = String.Format("{0}\\{1}", settings.getWorkingDir(), id); if (!Directory.Exists(path)) @@ -224,8 +227,7 @@ namespace AudioRecorder countDownTimer.Start(); } - private void SetCurrentFileNameAndPath(string currentFileName, string path) - { + private void SetCurrentFileNameAndPath(string currentFileName, string path) { String filePath = String.Format("{0}\\{1}", path, currentFileName); int i = 0; this.currentFileName = currentFileName; @@ -238,12 +240,10 @@ namespace AudioRecorder } - void timer_Tick(object sender, EventArgs e) - { + void timer_Tick(object sender, EventArgs e) { recordButton.Text = countDown.ToString(); countDown -= 1; - if (countDown < 0) - { + if (countDown < 0) { countDownTimer.Stop(); recordButton.Text = StringResources.RECORD; startRecord(); @@ -251,64 +251,51 @@ namespace AudioRecorder } } - private void setToolTipToFileNameLabel(String filePath) - { + private void setToolTipToFileNameLabel(String filePath) { ToolTip toolTip = new ToolTip(); String uncPath = String.Format("{0}{1}{2}", settings.getUncPath(), Path.DirectorySeparatorChar, currentFileName); String tip = String.Format("{0}\n{1}", filePath, uncPath); toolTip.SetToolTip(fileNameLabel, tip); } - private void selectAudioButton_Click(object sender, EventArgs e) - { + private void selectAudioButton_Click(object sender, EventArgs e) { showAudioDeviceSelectorForm(); } - private void showAudioDeviceSelectorForm() - { + private void showAudioDeviceSelectorForm() { selectorForm = new AudioDeviceSelectorForm(this); if (!selectorForm.isDisposed()) selectorForm.ShowDialog(); } - private void MainForm_FormClosing(object sender, FormClosingEventArgs e) - { - if (recording) - { + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { + if (recording) { DialogResult result = MessageBox.Show(StringResources.ARE_YOU_SURE_TO_QUIT_DURING_RECORDING, StringResources.EXIT_TITLE, MessageBoxButtons.YesNo); - if (result == DialogResult.Yes) - { + if (result == DialogResult.Yes) { stopRecording(); deleteTemporariFiles(); - } - else + } else e.Cancel = true; - } - else - { + } else { if (String.IsNullOrEmpty(settings.getAudioDeviceName())) settings.addSelectedAudio(selectedAudioName, CONFIG_FILE); deleteTemporariFiles(); } } - private void deleteTemporariFiles() - { - if (recorder != null) - { + private void deleteTemporariFiles() { + if (recorder != null) { List createdFiles = recorder.getCreatedFiles(); fileWorker.deleteFiles(createdFiles); } } - public void disableRecordButton() - { + public void disableRecordButton() { recordButton.Enabled = false; } - private void playButton_Click(object sender, EventArgs e) - { + private void playButton_Click(object sender, EventArgs e) { Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = new FileInfo(currentFilePath).FullName; @@ -316,8 +303,7 @@ namespace AudioRecorder process.Start(); } - private void volumeTrackBar_ValueChanged(object sender, EventArgs e) - { + private void volumeTrackBar_ValueChanged(object sender, EventArgs e) { TrackBar trackbar = sender as TrackBar; if (trackbar == null) return; @@ -327,15 +313,13 @@ namespace AudioRecorder currentDevice.AudioEndpointVolume.MasterVolumeLevel = value; } - private void pauseButton_Click(object sender, EventArgs e) - { + private void pauseButton_Click(object sender, EventArgs e) { pausing = !pausing; recorder.pauseRecording(pausing); timeCodeWorker.Pause(pausing); } - public void volumeChanged(object sender, EventArgs e) - { + public void volumeChanged(object sender, EventArgs e) { TrackBar trackbar = sender as TrackBar; if (trackbar == null) return; diff --git a/client/AudioRecorder/WavRecorder.cs b/client/AudioRecorder/WavRecorder.cs index 73b70acf..56c38fd5 100644 --- a/client/AudioRecorder/WavRecorder.cs +++ b/client/AudioRecorder/WavRecorder.cs @@ -58,14 +58,6 @@ namespace AudioRecorder { if (!pausing) { waveWriter.Write(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); - try { - int panelHeight = (int)Math.Round(device.AudioMeterInformation.MasterPeakValue * 100);//(device.AudioMeterInformation.MasterPeakValue) * 100; - Debug.WriteLine(string.Format("panelHeight {0}", panelHeight)); - mainForm.setPanelSizeHeight(panelHeight); - } - catch (Exception ex) { - Debug.WriteLine(ex.Message); - } } }