Ejemplo n.º 1
0
        public ActionResult GetMelodicDrillEx(string doNoteName, int type)
        {
            L1C5MelodicDrillType drillType = (L1C5MelodicDrillType)type;
            MemoryStream         wavStream = GetMelodicDrillEx(doNoteName, drillType);

            wavStream.WavToMp3File(out string fileName);
            return(Redirect($"~/Temp/{fileName}"));
        }
Ejemplo n.º 2
0
        private MemoryStream GetMelodicDrillEx(string doNoteName, L1C5MelodicDrillType drillType)
        {
            double bpm = double.Parse(ConfigurationManager.AppSettings["BPM"]);
            double quarterNoteMillis = (60 / bpm) * 1000;
            double eighthNoteMillis  = quarterNoteMillis / 2;

            TimeSpan eighthNoteDuration  = TimeSpan.FromMilliseconds(eighthNoteMillis);
            TimeSpan quarterNoteDuration = eighthNoteDuration.Add(eighthNoteDuration);
            TimeSpan wholeNoteDuration   = quarterNoteDuration.Add(quarterNoteDuration).Add(quarterNoteDuration).Add(quarterNoteDuration);

            string doFileName = NAudioHelper.GetFileNameFromNoteName(doNoteName);

            doFileName = Path.GetFileName(doFileName);
            int doNoteNumber = int.Parse(doFileName.Split('.')[0]);

            ISampleProvider note1, note2, note3, note4, note5, note6;

            switch (drillType)
            {
                #region 4ths.

            case L1C5MelodicDrillType.DoDoDoFaFaMi4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.ReReSoSoSoSo4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, quarterNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, quarterNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, eighthNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, eighthNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.MiMiMiLaLaSo4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.FaFaTiTiTiDo4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, quarterNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, eighthNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, eighthNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.SoSoSoDoDoDo4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.LaLaReReReDo4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, quarterNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, eighthNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, eighthNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.TiTiTiMiMiMi4:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, wholeNoteDuration);
                break;

                #endregion 4ths.

                #region 5ths.

            case L1C5MelodicDrillType.DoDoDoSoSoSo5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.ReReLaLaLaSo5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, quarterNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, eighthNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, eighthNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.MiMiMiTiTiDo5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.FaFaDoDoDoDo5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, quarterNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, eighthNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, eighthNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.SoSoSoReReDo5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.LaLaMiMiMiMi5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, quarterNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, quarterNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, eighthNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, eighthNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, wholeNoteDuration);
                break;

            case L1C5MelodicDrillType.FaFaFaTiTiDo5:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, quarterNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, eighthNoteDuration);
                note3 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, eighthNoteDuration);
                note4 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.DownMinor2nd, quarterNoteDuration);
                note5 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.DownMinor2nd, quarterNoteDuration);
                note6 = NAudioHelper.GetSampleProvider(doNoteNumber, wholeNoteDuration);
                break;

                #endregion 5ths.

            default:
                throw new NotSupportedException($"L1C5MelodicDrillType '{drillType}' is not supported.");
            }

            var phrase = note1
                         .FollowedBy(note2)
                         .FollowedBy(note3)
                         .FollowedBy(note4)
                         .FollowedBy(note5)
                         .FollowedBy(note6);

            var stwp = new SampleToWaveProvider(phrase);

            MemoryStream wavStream = new MemoryStream();
            WaveFileWriter.WriteWavFileToStream(wavStream, stwp);
            wavStream.Position = 0;
            return(wavStream);
        }
Ejemplo n.º 3
0
        private MemoryStream GetMelodicInterval(string doNoteName, L1C5MelodicDrillType drillType)
        {
            double   bpm = double.Parse(ConfigurationManager.AppSettings["BPM"]);
            double   quarterNoteMillis = (60 / bpm) * 1000;
            TimeSpan halfNoteDuration  = TimeSpan.FromMilliseconds(quarterNoteMillis * 2);

            string doFileName = NAudioHelper.GetFileNameFromNoteName(doNoteName);

            doFileName = Path.GetFileName(doFileName);
            int doNoteNumber = int.Parse(doFileName.Split('.')[0]);

            ISampleProvider note1, note2;

            switch (drillType)
            {
                #region 4ths.

            case L1C5MelodicDrillType.DoFa4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.ReSo4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.MiLa4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.FaTi4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.SoDo4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.LaRe4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.TiMi4Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.FaDo4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.SoRe4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.LaMi4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.TiFa4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.DoSo4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.ReLa4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.MiTi4Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                break;

                #endregion 4ths.

                #region 5ths.

            case L1C5MelodicDrillType.DoSo5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.ReLa5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.MiTi5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.FaDo5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.SoRe5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.LaMi5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.TiFa5Asc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect11th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.SoDo5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.LaRe5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor2nd, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.TiMi5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor3rd, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.DoFa5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfectOctave, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect4th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.ReSo5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor9th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect5th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.MiLa5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor10th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor6th, halfNoteDuration);
                break;

            case L1C5MelodicDrillType.FaTi5Desc:
                note1 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpPerfect11th, halfNoteDuration);
                note2 = NAudioHelper.GetSampleProvider(doNoteNumber + Interval.UpMajor7th, halfNoteDuration);
                break;

                #endregion 5ths.

            default:
                throw new NotSupportedException($"L1C5MelodicDrillType '{drillType}' is not supported.");
            }

            var phrase = note1
                         .FollowedBy(note2);

            var stwp = new SampleToWaveProvider(phrase);

            MemoryStream wavStream = new MemoryStream();
            WaveFileWriter.WriteWavFileToStream(wavStream, stwp);
            wavStream.Position = 0;
            return(wavStream);
        }