Example #1
0
        public FClip AddLastXSecondsToList()
        {
            //so easy just take last5 seconds of recording and put into an FClip object and push to tree
            string fileName = "" + GetCurrentTime() + ".wav";

            byte[] byteDataInCorrectOrder;
            using (WaveFileWriter w = new WaveFileWriter(SaveDirectory + fileName, capture.WaveFormat))
            {
                byteDataInCorrectOrder = shifter.GetDataInCorrectOrder();
                w.Write(byteDataInCorrectOrder, 0, byteDataInCorrectOrder.Length);
            }

            FClip clip = new FClip(byteDataInCorrectOrder, fileName);

            clips.Add(clip);
            return(clip);
        }
Example #2
0
        public FClip AddRandomCustomFileToList()
        {
            //specialname;
            //specialbuffer;

            byte[] copyboy = new byte[specialbuffer.Length];
            Array.Copy(specialbuffer, copyboy, specialbuffer.Length);

            using (WaveFileWriter w = new WaveFileWriter(SaveDirectory + specialname, capture.WaveFormat))
            {
                w.Write(copyboy, 0, copyboy.Length);
            }

            FClip clip = new FClip(specialbuffer, String.Copy(specialname));

            clips.Add(clip);
            return(clip);
        }
Example #3
0
 public void SaveToFile(FClip clip)
 {
     //selected by UI
 }
Example #4
0
 //plays sound thru mic
 public void PlayThroughMic(FClip clip)
 {
     //idk how yet
 }
Example #5
0
 //plays the selected sound back through the speaker
 public void Listen(FClip clip)
 {
 }
Example #6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            switch (button.Name)
            {
            case "StartRecord":
            {
                if (clipper.stopbuttonisntpressed == true)
                {
                    log("its recording already idiot");
                    return;
                }
                log("manual recording started.");
                ugh = new Thread(new ThreadStart(() =>
                    {
                        string randomfilenamepls = randomnamereeee();
                        clipper.StartRecordingSpecial(randomfilenamepls);
                        clipper.recordingSpecialThread.Join();
                        log("manual recording ended. saved to " + randomfilenamepls);
                    }));
                ugh.Start();
            }
            break;

            case "EndRecord":
            {
                clipper.StopRecordingSpecial();
                ugh.Join();
                FClip clip = clipper.AddRandomCustomFileToList();
                ListBoxObject.Items.Add(clipper.AddAndMapPath(clip.fileName));
            }
            break;

            case "RecordButton":
            {
                FClip clip = clipper.AddLastXSecondsToList();
                ListBoxObject.Items.Add(clipper.AddAndMapPath(clip.fileName));
                Console.WriteLine(clip.fileName + " added.");
            }
            break;

            case "SaveButton":
                if (((string)(ListBoxObject.SelectedValue)) == null)
                {
                    Console.WriteLine("Nothing selected");
                    return;
                }
                for (int n = -1; n < WaveOut.DeviceCount; n++)
                {
                    var caps = WaveOut.GetCapabilities(n);
                    Console.WriteLine(caps.ProductName);
                }
                break;

            case "ListenButton":
            {
                if (((string)(ListBoxObject.SelectedValue)) == null)
                {
                    Console.WriteLine("Nothing selected");
                    return;
                }

                string SelectedName = (string)(ListBoxObject.SelectedValue);
                Console.WriteLine("Listening to " + SelectedName);
                Thread thread = new Thread(new ParameterizedThreadStart((__SelectedName) =>
                    {
                        string _SelectedName = (string)__SelectedName;
                        //https://github.com/naudio/NAudio
                        try
                        {
                            using (var audioFile = new AudioFileReader(clipper.GetPath(_SelectedName)))
                            {
                                int selDevice = -1;
                                for (int n = -1; n < WaveOut.DeviceCount; n++)
                                {
                                    var caps = WaveOut.GetCapabilities(n);
                                    if (caps.ProductName.Contains("Headset Earphone"))
                                    {
                                        selDevice = n;
                                        break;
                                    }
                                }
                                using (var outputDevice = new WaveOutEvent()
                                {
                                    DeviceNumber = selDevice
                                })
                                {
                                    outputDevice.Init(audioFile);
                                    outputDevice.Volume = (float)percentagevolume;
                                    outputDevice.Play();
                                    while (outputDevice.PlaybackState == PlaybackState.Playing)
                                    {
                                        Thread.Sleep(1000);
                                    }
                                }
                            }
                        }
                        catch (System.Runtime.InteropServices.COMException e3)
                        { Console.WriteLine(e3); }
                    }));
                thread.Start(SelectedName);
            }
            break;

            case "PlayButton":
            {
                try
                {
                    if (((string)(ListBoxObject.SelectedValue)) == null)
                    {
                        Console.WriteLine("Nothing selected");
                        return;
                    }
                    string SelectedName = (string)(ListBoxObject.SelectedValue);
                    Console.WriteLine("Playing " + SelectedName);
                    Thread thread = new Thread(new ParameterizedThreadStart((__SelectedName) =>
                        {
                            string _SelectedName = (string)__SelectedName;
                            //https://github.com/naudio/NAudio

                            try
                            {
                                using (var audioFile = new AudioFileReader(clipper.GetPath(_SelectedName)))
                                {
                                    int selDevice = -1;
                                    for (int n = -1; n < WaveOut.DeviceCount; n++)
                                    {
                                        var caps = WaveOut.GetCapabilities(n);
                                        if (caps.ProductName.Contains("CABLE Input"))
                                        {
                                            selDevice = n;
                                            break;
                                        }
                                    }
                                    using (var outputDevice = new WaveOutEvent()
                                    {
                                        DeviceNumber = selDevice
                                    })
                                    {
                                        outputDevice.Init(audioFile);
                                        outputDevice.Volume = (float)percentagevolume;
                                        outputDevice.Play();
                                        while (outputDevice.PlaybackState == PlaybackState.Playing)
                                        {
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
                            catch (System.Runtime.InteropServices.COMException e3)
                            { Console.WriteLine(e3); }
                            catch (Exception e4)
                            {
                                Console.WriteLine(e4);
                            }
                        }));
                    thread.Start(SelectedName);
                    KillableThreads.Add(thread);
                }catch (Exception e2)
                {
                    Console.WriteLine(e2.StackTrace);
                }
            }
            break;

            case "KillButton":
                for (int i = 0; i < KillableThreads.Count; i++)
                {
                    KillableThreads[i].Abort();
                }
                KillableThreads.Clear();
                break;

            case "CloseButton":
                try
                {
                    SetDeviceToAudio2();
                }
                catch { }
                try
                {
                    chromeDriver.Close();
                }
                catch { }
                Environment.Exit(0);
                break;

            case "LoadButton":
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = true;
                ofd.DefaultExt  = ".wav";
                ofd.Filter      = "soundfiles (.wav)|*.wav";

                if (ofd.ShowDialog() == true)
                {
                    string[] fileNames = new string[ofd.FileNames.Length];
                    string[] pathNames = new string[ofd.FileNames.Length];
                    for (int i = 0; i < fileNames.Length; i++)
                    {
                        fileNames[i] = System.IO.Path.GetFileName(ofd.FileNames[i]);
                        pathNames[i] = System.IO.Path.GetDirectoryName(ofd.FileName);
                        ListBoxObject.Items.Add(clipper.AddAndMapPath(pathNames[i] + "\\" + fileNames[i]));
                        Console.WriteLine("Loaded " + pathNames[i] + "\\" + fileNames[i] + ".");
                    }
                }
                break;

            case "RenameButton":
            {
                if (((string)(ListBoxObject.SelectedValue)) == null)
                {
                    Console.WriteLine("Nothing selected");
                    return;
                }
                string SelectedName = (string)(ListBoxObject.SelectedValue);

                RetardBox.Visibility = Visibility.Visible;

                RenamePath      = clipper.GetPath(SelectedName);
                RenameShortName = String.Copy(SelectedName);

                string dispName = "";
                if (SelectedName.StartsWith(":") && SelectedName.Length != 1)
                {
                    dispName = SelectedName.Substring(1);
                }
                else
                {
                    dispName = SelectedName;
                }


                NameInputHandle.Text = dispName;
            }
            break;

            case "YesButton":

                string textToFix = NameInputHandle.Text;
                //remove extension from text if there is one
                if (textToFix.Contains("."))
                {
                    textToFix = textToFix.Substring(0, textToFix.IndexOf('.'));
                }

                //save the old extension
                string correctExtensionPlusDot = RenamePath.Substring(RenamePath.IndexOf('.'));
                if (textToFix.StartsWith(":"))
                {
                    return;
                }

                //append the old extension to the new text
                string renamedPath = RenamePath.Substring(0, RenamePath.LastIndexOf("\\"))
                                     + "\\" + textToFix + correctExtensionPlusDot;
                try
                {
                    System.IO.File.Move(RenamePath, renamedPath);

                    //now fix ui to reflect changes
                    ListBoxObject.Items[ListBoxObject.SelectedIndex] = clipper.Rename(RenamePath, renamedPath,
                                                                                      RenameShortName.StartsWith(":"), textToFix + correctExtensionPlusDot);
                }
                catch (Exception ere3)
                {
                    Console.Error.WriteLine("crashmessage=" + ere3.Message + "\r\n" + ere3.StackTrace);
                }
                RetardBox.Visibility = Visibility.Hidden;

                break;

            case "NoButton":
                RetardBox.Visibility = Visibility.Hidden;
                break;
            }
        }