Exemple #1
0
        /// <summary>
        /// Adds recorded or generated harmony to pre-recorded melody and beat.
        /// Stores the result in the original file.
        /// </summary>
        /// <param name="manual">Should harmony be added manually (as opposed to automatic generation)</param>
        public void AddHarmony(bool manual)
        {
            if (scale == null)
            {
                throw new ApplicationException("No scale selected");
            }

            // remove previously added harmony
            harmonyEpochs = new List <Epoch> {
            };
            RegenerateRecording();

            if (manual)
            {
                // adjust volume of recording
                recordingChannel.Volume = 2.5f;

                ManualHarmonyForm harmonyForm = new ManualHarmonyForm(this);

                harmonyProvider = new MixingWaveProvider32(new List <WaveChannel32> {
                    PitchSelector.GetWavePlayer(Pitch.Empty, session.WaveForm).Channel
                });
                harmonyOutput = new DirectSoundOut();
                harmonyOutput.Init(harmonyProvider);
                harmonyOutput.Play();

                harmonyForm.ShowDialog();
                RegenerateRecording();
            }
        }
Exemple #2
0
        private Session()
        {
            WaveForm = WaveForms.SineWave;

            // set all frequencies as not-playing
            CurrentlyPlayingPitches = new bool[Enum.GetNames(typeof(Pitch)).Length];
            foreach (Pitch frequency in Enum.GetValues(typeof(Pitch)))
            {
                CurrentlyPlayingPitches[(int)frequency] = false;
            }

            // initialize mixer with "silence" playing
            SoundMixer = new MixingWaveProvider32(new List <WaveChannel32> {
                PitchSelector.GetWavePlayer(Pitch.Empty, WaveForm).Channel
            });
            CurrentlyPlayingPitches[(int)Pitch.Empty] = true;

            // initialize output
            SoundOutput = new DirectSoundOut();
            SoundOutput.Init(SoundMixer);
            SoundOutput.Play();

            // set beat as not-playing
            BeatPlaying = false;

            // initialize recording to placeholder instance
            recorder    = RecorderPlaceholder.Instance;
            IsRecording = false;
        }
Exemple #3
0
        /// <summary>
        /// Plays given chord.
        /// </summary>
        /// <param name="chordName">Name of chord played</param>
        public void PlayChord(ChordName chordName)
        {
            Chord chord = new Chord(scale, chordName);

            foreach (Pitch pitch in chord.Tones)
            {
                harmonyProvider.AddInputStream(PitchSelector.GetWavePlayer(pitch, session.WaveForm).Channel);
            }
            lastChord = chord;
        }
Exemple #4
0
 /// <summary>
 /// Stops playing currently played chord.
 /// </summary>
 public void StopChord()
 {
     if (lastChord != null)
     {
         foreach (Pitch pitch in lastChord.Tones)
         {
             harmonyProvider.RemoveInputStream(PitchSelector.GetWavePlayer(pitch, session.WaveForm).Channel);
         }
     }
     lastChord = null;
 }
Exemple #5
0
        private void ResetOutput()
        {
            SoundOutput.Dispose();

            SoundMixer = new MixingWaveProvider32(new List <WaveChannel32> {
                PitchSelector.GetWavePlayer(Pitch.Empty, WaveForm).Channel
            });
            SoundOutput = new DirectSoundOut();
            SoundOutput.Init(SoundMixer);
            SoundOutput.Play();
        }
Exemple #6
0
        /// <summary>
        /// Stop playing given pitch
        /// </summary>
        /// <param name="pitch">Pitch</param>
        public void StopPlayingPitch(Pitch pitch)
        {
            // alert recorder that a change has been made
            UpdateRecorder();

            // do nothing if no tone was released
            if (pitch == Pitch.Empty)
            {
                return;
            }

            WavePlayer inputStream = PitchSelector.GetWavePlayer(pitch, WaveForm);

            SoundMixer.RemoveInputStream(inputStream.Channel);
            CurrentlyPlayingPitches[(int)pitch] = false;
        }
Exemple #7
0
        /// <summary>
        /// Starts playing the specified pitch
        /// </summary>
        /// <param name="pitch">Pitch</param>
        public void StartPlayingPitch(Pitch pitch)
        {
            // do nothing if no tone is added
            if (pitch == Pitch.Empty)
            {
                return;
            }

            if (!CurrentlyPlayingPitches[(int)pitch])
            {
                UpdateRecorder();

                WavePlayer inputStream = PitchSelector.GetWavePlayer(pitch, WaveForm);
                SoundMixer.AddInputStream(inputStream.Channel);
                CurrentlyPlayingPitches[(int)pitch] = true;
            }
        }
Exemple #8
0
 /// <summary>
 /// Returns WavePlayer corresponding to key and wave form.
 /// </summary>
 public static WavePlayer GetWavePlayerFromKey(Keys key, WaveFormEquation waveForm)
 => PitchSelector.GetWavePlayer(GetPitchFromKey(key), waveForm);