示例#1
0
 /// <summary>
 /// Updates the preset values of the given present control, with the current session values
 /// </summary>
 /// <param name="presetControl"></param>
 private void UpdatePresetValues(PresetControl presetControl)
 {
     presetControl.PresetData.Tempo = m_practiceSharpLogic.Tempo;
     presetControl.PresetData.Pitch = m_practiceSharpLogic.Pitch;
     presetControl.PresetData.Volume = m_practiceSharpLogic.Volume;
     presetControl.PresetData.LoEqValue = m_practiceSharpLogic.EqualizerLoBand;
     presetControl.PresetData.MedEqValue = m_practiceSharpLogic.EqualizerMedBand;
     presetControl.PresetData.HiEqValue = m_practiceSharpLogic.EqualizerHiBand;
     presetControl.PresetData.CurrentPlayTime = m_practiceSharpLogic.CurrentPlayTime;
     presetControl.PresetData.StartMarker = m_practiceSharpLogic.StartMarker;
     presetControl.PresetData.EndMarker = m_practiceSharpLogic.EndMarker;
     presetControl.PresetData.Cue = m_practiceSharpLogic.Cue;
     presetControl.PresetData.Loop = m_practiceSharpLogic.Loop;
     presetControl.PresetData.Description = presetControl.PresetDescription;
     presetControl.PresetData.TimeStretchProfile = m_practiceSharpLogic.TimeStretchProfile;
     presetControl.PresetData.RemoveVocals = m_practiceSharpLogic.SuppressVocals;
 }
示例#2
0
        /// <summary>
        /// PresetSelected Event handler - Handles a preset select request (user clicking on preset requesting to activate it)
        /// As a result the preset values are applied
        /// Note: The preset can be selected even if it is active - in this case the values will revert to the last saved values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void presetControl_PresetSelected(object sender, EventArgs e)
        {
            bool isPlaying = (m_practiceSharpLogic.Status == PracticeSharpLogic.Statuses.Playing);

            if (isPlaying)
            {
                m_practiceSharpLogic.Pause();
                TempMaskOutPlayTimeTrackBar();
            }
            try
            {
                m_currentPreset = sender as PresetControl;
                foreach (PresetControl presetControl in m_presetControls.Values)
                {
                    if (presetControl != m_currentPreset)
                    {
                        presetControl.State = PresetControl.PresetStates.Off;
                    }
                }

                PresetData presetData = m_currentPreset.PresetData;

                ApplyPresetValueUIControls(presetData);
            }
            finally
            {
                if (isPlaying) m_practiceSharpLogic.Play();
            }
        }
示例#3
0
        /// <summary>
        /// Open the given file
        /// </summary>
        /// <param name="filename"></param>
        private bool OpenFile(string filename, bool autoPlay)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                if (!File.Exists(filename))
                {
                    MessageBox.Show("File does not exist: " + filename, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }

                playTimeUpdateTimer.Enabled = false;
                m_practiceSharpLogic.Stop();

                m_mruManager.Add(filename);

                Properties.Settings.Default.LastFilename = filename;
                Properties.Settings.Default.Save();

                // Reset current UI Controls
                foreach (PresetControl presetControl in m_presetControls.Values)
                {
                    presetControl.Reset( false );
                }
                ApplyPresetValueUIControls(m_presetControls["1"].PresetData);
                m_currentFilename = filename;
                filenameToolStripStatusLabel.Text = Path.GetFileName( filename );
                m_practiceSharpLogic.LoadFile(filename);

                // Load Presets Bank for this input file
                m_presetBankFile = new PresetBankFile(m_appDataFolder,m_appVersion.ToString(),m_currentFilename);
                string activePresetId = m_presetBankFile.LoadPresetsBank(m_presetControls);

                // If no preset is active, select the first one by default
                if (activePresetId == null)
                    activePresetId = "1";

                m_currentPreset = m_presetControls[activePresetId];
                m_currentPreset.State = PresetControl.PresetStates.Selected;

                EnableControls(true);

                playDurationLabel.Text =
                       string.Format("{0}:{1}", m_practiceSharpLogic.FilePlayDuration.Minutes.ToString("00"),
                                    m_practiceSharpLogic.FilePlayDuration.Seconds.ToString("00"));
                play1QDurationLabel.Text =
                       string.Format("{0}:{1}", (m_practiceSharpLogic.FilePlayDuration.TotalSeconds / 4 / 60).ToString("00"),
                                    (m_practiceSharpLogic.FilePlayDuration.Seconds / 4).ToString("00"));
                play2QDurationLabel.Text =
                       string.Format("{0}:{1}", (m_practiceSharpLogic.FilePlayDuration.Minutes / 2).ToString("00"),
                                    (m_practiceSharpLogic.FilePlayDuration.Seconds / 2).ToString("00"));
                play3QDurationLabel.Text =
                       string.Format("{0}:{1}", (m_practiceSharpLogic.FilePlayDuration.TotalSeconds * 3 / 4 / 60).ToString("00"),
                                    (m_practiceSharpLogic.FilePlayDuration.Seconds * 3 / 4).ToString("00"));

                if (autoPlay)
                {
                    playPauseButton.Image = Resources.Pause_Normal;
                    m_practiceSharpLogic.Play();
                }
            }
            finally
            {
                playTimeUpdateTimer.Enabled = true;
                Cursor.Current = Cursors.Default;
            }

            return true;
        }
示例#4
0
        /// <summary>
        /// PresetSaveSelected Event handler - Handles a preset save request (user clicks on preset when Write Mode is on, i.e. Red Leds are turned on)
        /// As a result the preset is saved into the preset bank file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void presetControl_PresetSaveSelected(object sender, EventArgs e)
        {
            m_currentPreset = sender as PresetControl;

            foreach (PresetControl presetControl in m_presetControls.Values)
            {
                if (presetControl != m_currentPreset)
                {
                    presetControl.State = PresetControl.PresetStates.Off;
                }
                else
                {
                    if (presetControl.PresetData.Description == string.Empty)
                    {
                        presetControl.ChangeDescription();
                    }

                    UpdatePresetValues(presetControl);
                }
            }

            // (Re-)Write preset bank file
            RewritePresetsBankFile();

            if (m_tempSavePausePlay)
            {
                playPauseButton.Enabled = true;
                m_practiceSharpLogic.Play();
                m_tempSavePausePlay = false;
            }
            m_writeMode = false;
        }
示例#5
0
        /// <summary>
        /// Loads the presets from the preset bank file
        /// </summary>
        /// <returns>
        /// The active preset Id
        /// </returns>
        public string LoadPresetsBank(Dictionary <string, PresetControl> presetControls)
        {
            if (!File.Exists(m_presetsBankFilename))
            {
                return(null);
            }

            try
            {
                // Loads the presets bank XML file
                XmlDocument doc = new XmlDocument();
                doc.Load(m_presetsBankFilename);

                XmlElement  root            = doc.DocumentElement;
                XmlNode     presetsBankNode = root.SelectSingleNode("/" + PresetBankFile.XML_Node_Root + "/" + PresetBankFile.XML_Node_PresetsBank);
                string      activePresetId  = presetsBankNode.Attributes[PresetBankFile.XML_Attr_ActivePreset].Value;
                XmlNodeList presetNodes     = presetsBankNode.SelectNodes(PresetBankFile.XML_Node_Preset);
                // Load all preset nodes
                foreach (XmlNode presetNode in presetNodes)
                {
                    string presetId = presetNode.Attributes[PresetBankFile.XML_Attr_Id].Value;
                    // Load XML values into PresetData object
                    PresetData presetData = presetControls[presetId].PresetData;
                    presetData.Tempo  = ReadXMLAttributeFloat(presetNode, PresetBankFile.XML_Attr_Tempo, PresetData.DefaultTempo);
                    presetData.Pitch  = ReadXMLAttributeFloat(presetNode, PresetBankFile.XML_Attr_Pitch, PresetData.DefaultPitch);
                    presetData.Volume = ReadXMLAttributeFloat(presetNode, PresetBankFile.XML_Attr_Volume, Properties.Settings.Default.DefaultVolume);

                    presetData.LoEqValue  = ReadXMLAttributeFloat(presetNode, PresetBankFile.XML_Attr_LoEq, PresetData.DefaultLoEq);
                    presetData.MedEqValue = ReadXMLAttributeFloat(presetNode, PresetBankFile.XML_Attr_MedEq, PresetData.DefaultMedEq);
                    presetData.HiEqValue  = ReadXMLAttributeFloat(presetNode, PresetBankFile.XML_Attr_HiEq, PresetData.DefaultHiEq);

                    presetData.CurrentPlayTime = TimeSpan.Parse(presetNode.Attributes[PresetBankFile.XML_Attr_PlayTime].Value);
                    presetData.StartMarker     = TimeSpan.Parse(presetNode.Attributes[PresetBankFile.XML_Attr_LoopStartMarker].Value);
                    presetData.EndMarker       = TimeSpan.Parse(presetNode.Attributes[PresetBankFile.XML_Attr_LoopEndMarker].Value);
                    presetData.Loop            = Convert.ToBoolean(presetNode.Attributes[PresetBankFile.XML_Attr_IsLoop].Value);
                    presetData.Cue             = TimeSpan.Parse(presetNode.Attributes[PresetBankFile.XML_Attr_Cue].Value);
                    presetData.Description     = Convert.ToString(presetNode.Attributes[PresetBankFile.XML_Attr_Description].Value);

                    TimeStretchProfile timeStretchProfile = TimeStretchProfileManager.DefaultProfile;
                    if (presetNode.Attributes[PresetBankFile.XML_Attr_TimeStretchProfileId] != null)
                    {
                        string timeStretchProfileId = Convert.ToString(presetNode.Attributes[PresetBankFile.XML_Attr_TimeStretchProfileId].Value);
                        if (!TimeStretchProfileManager.TimeStretchProfiles.TryGetValue(timeStretchProfileId, out timeStretchProfile))
                        {
                            // Handle a mismatched profile by using the default profile
                            timeStretchProfile = TimeStretchProfileManager.DefaultProfile;
                        }
                    }
                    presetData.TimeStretchProfile = timeStretchProfile;

                    if (presetNode.Attributes[PresetBankFile.XML_Attr_RemoveVocals] != null)
                    {
                        presetData.RemoveVocals = Convert.ToBoolean(presetNode.Attributes[PresetBankFile.XML_Attr_RemoveVocals].Value);
                    }

                    PresetControl presetControl = presetControls[presetId];
                    presetControl.PresetDescription = presetData.Description;
                }

                return(activePresetId);
            }
            catch (Exception ex)
            {
                m_logger.ErrorException("Failed loading Presets Bank for file: " + m_currentAudioFilename, ex);
                MessageBox.Show(null, "Failed loading Presets Bank for file: " + m_currentAudioFilename, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }