Example #1
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.Title           = "Testing Code Library";
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine(" Testing a code library to see it's uses ");
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine();
            Console.WriteLine();

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;

            SampleLibrary alg     = new SampleLibrary();
            double        number1 = 100;
            double        number2 = 50;
            double        result  = alg.Addition(number1, number2);

            Console.Write(number1);
            Console.Write(" + ");
            Console.Write(number2);
            Console.Write(" = ");
            Console.WriteLine(result);
        }
        private void mnuCopySample_Click(object sender, EventArgs e)
        {
            var samples = GetSelectedSamples();

            if (samples == null)
            {
                return;
            }

            var folder = FileDialogHelper.OpenFolder();

            if (folder == "")
            {
                return;
            }

            foreach (var sample in samples)
            {
                var source   = SampleLibrary.GetSampleFileName(sample);
                var filename = $"{sample.TrackArtist} - {sample.TrackTitle} - {sample.Description}";
                filename = FileSystemHelper.StripInvalidFileNameChars(filename) + Path.GetExtension(source);
                var destination = Path.Combine(folder, filename);
                FileSystemHelper.Copy(source, destination);
            }
        }
        private void LoadCurrentSamples()
        {
            lock (_player)
            {
                _player.Pause();
                var samples = GetSelectedSamples();
                if (samples == null || samples.Count == 0)
                {
                    return;
                }

                _player.UnloadAll();
                foreach (var sample in samples)
                {
                    var track = SampleLibrary.GetTrackFromSample(sample);

                    var filename = (track == null) ? sample.Filename : track.Filename;
                    if (!File.Exists(filename))
                    {
                        continue;
                    }

                    _player.AddSample(GetSampleKey(sample),
                                      filename,
                                      sample.Start,
                                      sample.Length,
                                      sample.Offset);
                }
            }
        }
        private void BtnReloadLibrary_Click(object sender, EventArgs e)
        {
            StopSamples();

            Cursor = Cursors.WaitCursor;

            SampleLibrary.LoadFromFiles();
            BindSamples();

            Cursor = Cursors.Default;
        }
        private void mnuCalculateKey_Click(object sender, EventArgs e)
        {
            StopSamples();

            foreach (var sample in GetSelectedSamples().Where(sample => sample.Key == ""))
            {
                SampleLibrary.CalculateSampleKey(sample);
            }

            SampleLibrary.SaveToCache();

            BindData();
        }
        public List <Sample> GetDisplayedSamples()
        {
            var criteria = new SearchCriteria();

            var loopTypeText = LoopFilter;

            if (loopTypeText.Contains("Primary"))
            {
                criteria.Primary  = true;
                criteria.LoopMode = LoopMode.FullLoop;
            }
            else if (loopTypeText != "")
            {
                criteria.Primary = false;
                if (loopTypeText.Contains("Start"))
                {
                    criteria.LoopMode = LoopMode.PartialLoopAnchorStart;
                }
                else if (loopTypeText.Contains("End"))
                {
                    criteria.LoopMode = LoopMode.PartialLoopAnchorEnd;
                }
                else if (loopTypeText == "Loop")
                {
                    criteria.LoopMode = LoopMode.FullLoop;
                }
            }

            var keyText = KeyFilter;

            if (keyText == "Atonal")
            {
                criteria.AtonalOnly = true;
                criteria.Key        = "";
            }
            else
            {
                criteria.Key        = KeyHelper.GetKeyFromDisplayKey(KeyFilter);
                criteria.AtonalOnly = false;
            }

            criteria.IncludeAtonal = IncludeAtonalFilter;

            criteria.MaxBpm = MaxBpm;
            criteria.MinBpm = MinBpm;

            criteria.SearchText = SearchFilter;
            var samples = SampleLibrary.GetSamples(criteria);

            return(samples);
        }
        private void EditSample()
        {
            var trackSampleLibrary = (TrackSampleLibrary)SampleLibrary;

            if (trackSampleLibrary == null)
            {
                return;
            }

            var sample = GetSelectedSample();

            if (sample == null)
            {
                return;
            }

            var track = SampleLibrary.GetTrackFromSample(sample);

            if (track == null)
            {
                return;
            }

            StopSamples();

            var initialSample = sample.Description;


            var form = new FrmEditTrackSamples
            {
                BassPlayer         = BassPlayer,
                Filename           = track.Filename,
                TrackSampleLibrary = trackSampleLibrary,
                Library            = trackSampleLibrary.TrackLibrary,
                InitialSample      = initialSample
            };

            var result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                BindData();
            }

            form.Dispose();
        }
        private void ExportSamples(List <Sample> samples)
        {
            StopSamples();

            Cursor = Cursors.WaitCursor;


            var folder = FileDialogHelper.OpenFolder();

            if (folder == "")
            {
                return;
            }

            ParallelHelper.ForEach(samples, sample =>
            {
                var track = SampleLibrary.GetTrackFromSample(sample);
                if (track == null)
                {
                    return;
                }

                var outPath = Path.Combine(folder, track.Genre);

                if (!Directory.Exists(outPath))
                {
                    Directory.CreateDirectory(outPath);
                }

                var outFile = FileSystemHelper.StripInvalidFileNameChars($"{sample.Bpm:000.00} - {sample.TrackArtist} - {sample.TrackTitle} - {sample.Description}.wav");

                outPath = Path.Combine(outPath, outFile);

                if (File.Exists(outPath))
                {
                    File.Delete(outPath);
                }

                AudioExportHelper.SavePartialAsWave(track.Filename, outPath, sample.Start, sample.Length, sample.Offset,
                                                    sample.Gain);
            });

            Cursor = Cursors.Default;
        }
 private void mnuExportAllSamples_Click(object sender, EventArgs e)
 {
     ExportSamples(SampleLibrary.GetSamples());
 }
        private string GetSampleKey(Sample sample)
        {
            var track = SampleLibrary.GetTrackFromSample(sample);

            return((track == null) ? sample.Filename : track.Description + " - " + sample.Description);
        }