d@0: using System; d@0: using System.Collections.Generic; d@0: using System.ComponentModel; d@0: using System.Diagnostics; d@0: using System.IO; d@0: using System.Linq; d@0: using System.Windows.Forms; d@0: using CsvHelper; d@0: d@0: namespace DeMaskingLT d@0: { d@0: public partial class ListenToAudio : Form d@0: { d@0: System.Media.SoundPlayer _player = new System.Media.SoundPlayer(); d@0: private PerceivedEmotion _perceivedEmotion; d@0: d@0: private String _track1FileName = "C:\\Users\\David\\Desktop\\PO-12 Samples\\PO-12 Mix - Not Cut.wav"; d@0: private String _track2FileName = "C:\\Users\\David\\Desktop\\PO-12 Samples\\PO-12 Techno Loop 1.wav"; d@0: private String _track3FileName = "C:\\Users\\David\\Desktop\\PO-12 Samples\\PO-12 Techno Loop 2.wav"; d@0: private String _track4FileName = "C:\\Users\\David\\Desktop\\PO-12 Samples\\PO-12 Techno Loop 3.wav"; d@0: private String _track5FileName = "C:\\Users\\David\\Desktop\\PO-12 Samples\\PO-12 Techno Loop 4.wav"; d@0: d@0: ExperimentData _experimentData = new ExperimentData(); d@0: List _results = new List(); d@0: private Logging _logger; d@0: d@0: private bool _track1Played = false; d@0: private bool _track2Played = false; d@0: private bool _track3Played = false; d@0: private bool _track4Played = false; d@0: private bool _track5Played = false; d@0: d@0: private Stopwatch _stopWatchListenToSong = new Stopwatch(); d@0: d@0: private int _track1TimesMoved = 0; d@0: private int _track2TimesMoved = 0; d@0: private int _track3TimesMoved = 0; d@0: private int _track4TimesMoved = 0; d@0: private int _track5TimesMoved = 0; d@0: d@0: private int _track1CurrentValue = 0; d@0: private int _track2CurrentValue = 0; d@0: private int _track3CurrentValue = 0; d@0: private int _track4CurrentValue = 0; d@0: private int _track5CurrentValue = 0; d@0: d@3: private int _testNumber = 4; d@0: d@0: public ListenToAudio() d@0: { d@0: InitializeComponent(); d@0: } d@0: d@0: private void trackBarTrack1_ValueChanged(object sender, EventArgs e) d@0: { d@0: textBoxTrack1.Text = trackBarTrack1.Value.ToString(); d@0: } d@0: d@0: private void trackBarTrack2_ValueChanged(object sender, EventArgs e) d@0: { d@0: textBoxTrack2.Text = trackBarTrack2.Value.ToString(); d@0: } d@0: d@0: private void trackBarTrack3_ValueChanged(object sender, EventArgs e) d@0: { d@0: textBoxTrack3.Text = trackBarTrack3.Value.ToString(); d@0: } d@0: d@0: private void trackBarTrack4_ValueChanged(object sender, EventArgs e) d@0: { d@0: textBoxTrack4.Text = trackBarTrack4.Value.ToString(); d@0: } d@0: d@0: private void trackBarTrack5_ValueChanged(object sender, EventArgs e) d@0: { d@0: textBoxTrack5.Text = trackBarTrack5.Value.ToString(); d@0: } d@0: d@0: private void backgroundWorkerAudio_DoWork(object sender, DoWorkEventArgs e) d@0: { d@0: if (sender.Equals(buttonPlayTrack1)) d@0: { d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = "Mix 1 is now playing"; d@0: } d@0: d@0: PlayMusic(_track1FileName); d@0: d@0: } d@0: else if (sender.Equals(buttonPlayTrack2)) d@0: { d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = "Mix 2 is now playing"; d@0: } d@0: d@0: PlayMusic(_track2FileName); d@0: d@0: } d@0: else if (sender.Equals(buttonPlayTrack3)) d@0: { d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = "Mix 3 is now playing"; d@0: } d@0: d@0: PlayMusic(_track3FileName); d@0: } d@0: else if (sender.Equals(buttonPlayTrack4)) d@0: { d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = "Mix 4 is now playing"; d@0: } d@0: d@0: PlayMusic(_track4FileName); d@0: d@0: } d@0: else if (sender.Equals(buttonPlayTrack5)) d@0: { d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = "Mix 5 is now playing"; d@0: } d@0: d@0: PlayMusic(_track5FileName); d@0: } d@0: } d@0: d@0: private void PlayMusic(String audioFile) d@0: { d@0: _player.Stop(); d@0: _player.SoundLocation = audioFile; d@0: _player.Play(); d@0: } d@0: d@0: private void trackBarTrack1_MouseDown(object sender, MouseEventArgs e) d@0: { d@0: CheckSumbitButtonEnabled(); d@0: backgroundWorkerAudio_DoWork(trackBarTrack1, null); d@0: } d@0: d@0: private void trackBarTrack2_MouseDown(object sender, MouseEventArgs e) d@0: { d@0: CheckSumbitButtonEnabled(); d@0: backgroundWorkerAudio_DoWork(trackBarTrack2, null); d@0: } d@0: d@0: private void trackBarTrack3_MouseDown(object sender, MouseEventArgs e) d@0: { d@0: CheckSumbitButtonEnabled(); d@0: backgroundWorkerAudio_DoWork(trackBarTrack3, null); d@0: } d@0: d@0: private void trackBarTrack4_MouseDown(object sender, MouseEventArgs e) d@0: { d@0: CheckSumbitButtonEnabled(); d@0: backgroundWorkerAudio_DoWork(trackBarTrack4, null); d@0: } d@0: d@0: private void trackBarTrack5_MouseDown(object sender, MouseEventArgs e) d@0: { d@0: CheckSumbitButtonEnabled(); d@0: backgroundWorkerAudio_DoWork(trackBarTrack5, null); d@0: } d@0: d@0: private void CheckSumbitButtonEnabled() d@0: { d@0: if (_track1Played && _track2Played && _track3Played && _track4Played && _track5Played) d@0: { d@0: buttonSubmit.Enabled = true; d@0: } d@0: } d@0: d@0: private void ListenToAudio_Load(object sender, EventArgs e) d@0: { d@0: d@0: this.CenterToScreen(); d@0: d@0: Name nameDialog = new Name(); d@0: String currentUser = String.Empty; d@0: String testType = String.Empty; d@0: d@0: this.Hide(); d@0: nameDialog.ShowDialog(this); d@0: d@0: if (nameDialog.radioButtonTestA.Checked) d@0: { d@0: testType = "A"; d@0: textBoxTestInstructions.Text = "Please rate the mixes in terms of your own overall preference."; d@0: } d@0: else if (nameDialog.radioButtonTestB.Checked) d@0: { d@0: testType = "B"; d@0: textBoxTestInstructions.Text = "Please rate the mixes in terms of the ability to distinguish the sources (i.e. the lack of masking)."; d@0: } d@0: d@0: nameDialog.ShowDialog(this); d@0: d@0: _experimentData.NameOfParticipant = nameDialog.tbName.Text; d@0: d@0: nameDialog.ShowDialog(this); d@0: d@0: //Create log file for Data d@0: _logger = new Logging(testType + "_" + _experimentData.NameOfParticipant + "_LTResults.txt", ","); d@0: d@0: d@0: string path = Directory.GetCurrentDirectory(); d@0: path = path + "\\Files.txt"; d@0: d@0: List audioFiles = new List(); d@0: d@0: try d@0: { d@0: using (var sr = new StreamReader(path)) d@0: { d@0: var reader = new CsvReader(sr); d@0: d@0: while (true) d@0: { d@0: reader.Configuration.HasHeaderRecord = false; d@0: var row = reader.Read(); d@0: if (reader.CurrentRecord == null) d@0: { d@0: break; d@0: } d@0: audioFiles.Add(reader.CurrentRecord[0]); d@0: } d@0: } d@0: d@0: } d@0: catch (Exception ex) d@0: { d@0: MessageBox.Show(ex.Message, this.Name, MessageBoxButtons.OK, MessageBoxIcon.Warning); d@0: throw; d@0: } d@0: d@0: int songIndex = 0; d@0: foreach (var pathAudio in audioFiles) d@0: { d@0: d@0: ExperimentData expdata = new ExperimentData(); d@0: string [] fileEntries = Directory.GetFiles(pathAudio, "*.wav"); d@0: d@0: foreach (string fileName in fileEntries) d@0: { d@0: d@0: _experimentData.Songs[songIndex].Add(fileName); d@0: d@0: } d@0: d@0: songIndex++; d@0: } d@0: d@0: d@0: //Randomise Everyting for the experiment d@0: var rnd = new Random(); d@0: _experimentData.Song1Mixes = _experimentData.Song1Mixes.OrderBy(x => rnd.Next()).ToList(); d@0: rnd = new Random(); d@0: _experimentData.Song2Mixes = _experimentData.Song2Mixes.OrderBy(x => rnd.Next()).ToList(); d@0: rnd = new Random(); d@0: _experimentData.Song3Mixes = _experimentData.Song3Mixes.OrderBy(x => rnd.Next()).ToList(); d@0: rnd = new Random(); d@0: _experimentData.Song4Mixes = _experimentData.Song4Mixes.OrderBy(x => rnd.Next()).ToList(); d@0: rnd = new Random(); d@0: _experimentData.Song5Mixes = _experimentData.Song5Mixes.OrderBy(x => rnd.Next()).ToList(); d@0: d@0: rnd = new Random(); d@0: _experimentData.Songs = _experimentData.Songs.OrderBy(x => rnd.Next()).ToList(); d@0: d@0: int songNum = _testNumber + 1; d@0: this.Text = "Experiment - Song " + songNum.ToString(); d@0: d@0: AssignSliders(); d@0: d@0: _stopWatchListenToSong.Reset(); d@0: _stopWatchListenToSong.Start(); d@0: } d@0: d@0: private void AssignSliders() d@0: { d@0: //TODO: Put in the real mixes and run the fuckin experiment. d@0: _track1FileName = _experimentData.Songs[_testNumber][0]; d@0: _track2FileName = _experimentData.Songs[_testNumber][1]; d@0: _track3FileName = _experimentData.Songs[_testNumber][2]; d@0: _track4FileName = _experimentData.Songs[_testNumber][3]; d@0: _track5FileName = _experimentData.Songs[_testNumber][4]; d@0: d@0: Random rnd = new Random(); d@0: trackBarTrack1.Value = rnd.Next(0, 100); d@0: trackBarTrack2.Value = rnd.Next(0, 100); d@0: trackBarTrack3.Value = rnd.Next(0, 100); d@0: trackBarTrack4.Value = rnd.Next(0, 100); d@0: trackBarTrack5.Value = rnd.Next(0, 100); d@0: d@0: _track1CurrentValue = trackBarTrack1.Value; d@0: _track2CurrentValue = trackBarTrack2.Value; d@0: _track3CurrentValue = trackBarTrack3.Value; d@0: _track4CurrentValue = trackBarTrack4.Value; d@0: _track5CurrentValue = trackBarTrack5.Value; d@0: d@0: _track1Played = false; d@0: _track2Played = false; d@0: _track3Played = false; d@0: _track4Played = false; d@0: _track5Played = false; d@0: d@0: _track1TimesMoved = 0; d@0: _track2TimesMoved = 0; d@0: _track3TimesMoved = 0; d@0: _track4TimesMoved = 0; d@0: _track5TimesMoved = 0; d@0: d@0: } d@0: d@0: private void buttonSubmit_Click(object sender, EventArgs e) d@0: { d@0: _player.Stop(); d@0: d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: d@0: _stopWatchListenToSong.Stop(); d@0: TimeSpan ts = _stopWatchListenToSong.Elapsed; d@0: d@0: // Format and display the TimeSpan value. d@0: string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", d@0: ts.Hours, ts.Minutes, ts.Seconds, d@0: ts.Milliseconds / 10); d@0: d@0: Result currentResult = new Result(_experimentData.NameOfParticipant, elapsedTime, d@0: new MixScore(Path.GetFileName(_track1FileName), trackBarTrack1.Value), _track1TimesMoved, d@0: new MixScore(Path.GetFileName(_track2FileName), trackBarTrack2.Value), _track2TimesMoved, d@0: new MixScore(Path.GetFileName(_track3FileName), trackBarTrack3.Value), _track3TimesMoved, d@0: new MixScore(Path.GetFileName(_track4FileName), trackBarTrack4.Value), _track4TimesMoved, d@0: new MixScore(Path.GetFileName(_track5FileName), trackBarTrack5.Value), _track5TimesMoved); d@0: _results.Add(currentResult); d@0: d@0: _logger.WriteLTData(currentResult); d@0: d@0: if (_testNumber == 4) d@0: { d@0: ThankYou thankYouDialog = new ThankYou("Thank you for taking part in this part of the experiment. Please continue to the next section."); // Show testDialog as a modal dialog and determine if DialogResult = OK. d@0: if (thankYouDialog.ShowDialog(this) == DialogResult.OK) d@0: { d@0: // Read the contents of testDialog's TextBox. d@0: d@0: } d@0: _logger.CloseFile(); d@0: _perceivedEmotion = new PerceivedEmotion(_experimentData.NameOfParticipant); d@0: _perceivedEmotion.Show(this); d@0: this.Hide(); d@0: } d@0: else d@0: { d@0: ThankYou thankYouDialog = new ThankYou(); // Show testDialog as a modal dialog and determine if DialogResult = OK. d@0: if (thankYouDialog.ShowDialog(this) == DialogResult.OK) d@0: { d@0: // Read the contents of testDialog's TextBox. d@0: d@0: } d@0: d@0: _testNumber++; d@0: int songNum = _testNumber + 1; d@0: this.Text = "Perceived Emotion Experiment - Song " + songNum.ToString(); d@0: AssignSliders(); d@0: _stopWatchListenToSong.Reset(); d@0: _stopWatchListenToSong.Start(); d@0: buttonSubmit.Enabled = false; d@0: } d@0: d@0: d@0: } d@0: d@0: private void buttonPlayTrack1_Click(object sender, EventArgs e) d@0: { d@0: _track1Played = true; d@0: CheckSumbitButtonEnabled(); d@0: timerStatusBar.Interval = 33000; d@0: timerStatusBar.Start(); d@0: backgroundWorkerAudio_DoWork(buttonPlayTrack1, null); d@0: } d@0: d@0: private void buttonPlayTrack2_Click(object sender, EventArgs e) d@0: { d@0: _track2Played = true; d@0: CheckSumbitButtonEnabled(); d@0: timerStatusBar.Interval = 33000; d@0: timerStatusBar.Start(); d@0: backgroundWorkerAudio_DoWork(buttonPlayTrack2, null); d@0: } d@0: d@0: private void buttonPlayTrack3_Click(object sender, EventArgs e) d@0: { d@0: _track3Played = true; d@0: CheckSumbitButtonEnabled(); d@0: timerStatusBar.Interval = 33000; d@0: timerStatusBar.Start(); d@0: backgroundWorkerAudio_DoWork(buttonPlayTrack3, null); d@0: } d@0: d@0: private void buttonPlayTrack4_Click(object sender, EventArgs e) d@0: { d@0: _track4Played = true; d@0: CheckSumbitButtonEnabled(); d@0: timerStatusBar.Interval = 33000; d@0: timerStatusBar.Start(); d@0: backgroundWorkerAudio_DoWork(buttonPlayTrack4, null); d@0: } d@0: d@0: private void buttonPlayTrack5_Click(object sender, EventArgs e) d@0: { d@0: _track5Played = true; d@0: CheckSumbitButtonEnabled(); d@0: timerStatusBar.Interval = 33000; d@0: timerStatusBar.Start(); d@0: backgroundWorkerAudio_DoWork(buttonPlayTrack5, null); d@0: } d@0: d@0: private void buttonStopTrack1_Click(object sender, EventArgs e) d@0: { d@0: _player.Stop(); d@0: d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: } d@0: d@0: private void buttonStopTrack2_Click(object sender, EventArgs e) d@0: { d@0: _player.Stop(); d@0: d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: } d@0: d@0: private void buttonStopTrack3_Click(object sender, EventArgs e) d@0: { d@0: _player.Stop(); d@0: d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: } d@0: d@0: private void buttonStopTrack4_Click(object sender, EventArgs e) d@0: { d@0: _player.Stop(); d@0: d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: } d@0: d@0: private void buttonStopTrack5_Click(object sender, EventArgs e) d@0: { d@0: _player.Stop(); d@0: d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: } d@0: d@0: private void timerStatusBar_Tick(object sender, EventArgs e) d@0: { d@0: timerStatusBar.Stop(); d@0: foreach (ToolStripStatusLabel label in statusStrip1.Items) d@0: { d@0: label.Text = ""; d@0: } d@0: } d@0: d@0: private void trackBarTrack1_MouseUp(object sender, MouseEventArgs e) d@0: { d@0: d@0: if (trackBarTrack1.Value != _track1CurrentValue) d@0: { d@0: _track1TimesMoved++; d@0: } d@0: d@0: _track1CurrentValue = trackBarTrack1.Value; d@0: } d@0: d@0: private void trackBarTrack2_MouseUp(object sender, MouseEventArgs e) d@0: { d@0: d@0: if (trackBarTrack2.Value != _track2CurrentValue) d@0: { d@0: _track2TimesMoved++; d@0: } d@0: d@0: _track2CurrentValue = trackBarTrack2.Value; d@0: } d@0: d@0: private void trackBarTrack3_MouseUp(object sender, MouseEventArgs e) d@0: { d@0: d@0: if (trackBarTrack3.Value != _track3CurrentValue) d@0: { d@0: _track3TimesMoved++; d@0: } d@0: d@0: _track3CurrentValue = trackBarTrack3.Value; d@0: } d@0: d@0: private void trackBarTrack4_MouseUp(object sender, MouseEventArgs e) d@0: { d@0: d@0: if (trackBarTrack4.Value != _track4CurrentValue) d@0: { d@0: _track4TimesMoved++; d@0: } d@0: d@0: _track4CurrentValue = trackBarTrack4.Value; d@0: } d@0: d@0: private void trackBarTrack5_MouseUp(object sender, MouseEventArgs e) d@0: { d@0: d@0: if (trackBarTrack5.Value != _track5CurrentValue) d@0: { d@0: _track5TimesMoved++; d@0: } d@0: d@0: _track5CurrentValue = trackBarTrack5.Value; d@0: } d@0: d@0: private void ListenToAudio_FormClosing(object sender, FormClosingEventArgs e) d@0: { d@0: _player.Stop(); d@0: _logger.CloseFile(); d@0: } d@0: } d@0: }