コード例 #1
0
ファイル: Recorder.cs プロジェクト: kszabova/cnthesizer
        /// <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();
            }
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: kszabova/cnthesizer
        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;
        }
コード例 #3
0
ファイル: Recorder.cs プロジェクト: kszabova/cnthesizer
        /// <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;
        }
コード例 #4
0
ファイル: Recorder.cs プロジェクト: kszabova/cnthesizer
 /// <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;
 }
コード例 #5
0
ファイル: Session.cs プロジェクト: kszabova/cnthesizer
        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();
        }
コード例 #6
0
ファイル: Session.cs プロジェクト: kszabova/cnthesizer
        /// <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;
        }
コード例 #7
0
ファイル: Session.cs プロジェクト: kszabova/cnthesizer
        /// <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;
            }
        }
コード例 #8
0
ファイル: KeyControls.cs プロジェクト: kszabova/cnthesizer
 /// <summary>
 /// Returns WavePlayer corresponding to key and wave form.
 /// </summary>
 public static WavePlayer GetWavePlayerFromKey(Keys key, WaveFormEquation waveForm)
 => PitchSelector.GetWavePlayer(GetPitchFromKey(key), waveForm);