private void dropSlope_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(!graph_loaded)
            {
                return;
            }

            int local_filter_index = int.Parse(((ComboBox)sender).Name.Substring(9));
            int global_filter_index = local_filter_index + starting_filter;

            BandPassFilter toolFilter = new BandPassFilter(0, 0, 0);

            TextBox txtFreq = (TextBox)(Controls.Find("txtFreq" + local_filter_index.ToString(), true)[0]);

            ComboBox dropFilter = (ComboBox)(Controls.Find("dropFilter" + local_filter_index.ToString(), true)[0]);

            if (((ComboBox)sender).SelectedIndex == 0)
            {
                if (dropFilter.SelectedIndex == 1)
                {
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new FirstOrderLowPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), 0.0, 0.0);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Type = FilterType.FirstOrderLowPass;
                }
                else
                {
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new FirstOrderHighPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), 0.0, 0.0);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Type = FilterType.FirstOrderHighPass;
                }

            }
            else
            {
                if (dropFilter.SelectedIndex == 1)
                {
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new SecondOrderLowPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), 0.0, 0.0);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Type = FilterType.SecondOrderLowPass;
                }
                else
                {
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new SecondOrderHighPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), 0.0, 0.0);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Type = FilterType.SecondOrderHighPass;
                }
            }

            lblFilterSelector0.Focus();

            RefreshAllFilters();

            SendFilterToParent(active_global_filter_index);
        }
        private void dropFilter_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (graph_loaded)
            {
                lblFilterSelector0.Focus();
            }

            int local_filter_index = int.Parse(((ComboBox) sender).Name.Substring(10));
            int global_filter_index = local_filter_index + starting_filter;
            // Change the handles to be on the one selected

            bool removing_filter = false; // Will be set to true so we can select new active filter if this one is going to FilterType.None

            bool bypass_value = ((PictureCheckbox)Controls.Find("chkBypass" + local_filter_index, true).First()).Checked;
            Label filterSelector = (Label)(Controls.Find("lblFilterSelector" + local_filter_index.ToString(), true)[0]);

            ComboBox dropSlope = (ComboBox)(Controls.Find("dropSlope" + local_filter_index.ToString(), true)[0]);

            TextBox txtFreq = (TextBox)(Controls.Find("txtFreq" + local_filter_index.ToString(), true)[0]);
            TextBox txtGain = (TextBox)(Controls.Find("txtGain" + local_filter_index.ToString(), true)[0]);
            TextBox txtQval = (TextBox)(Controls.Find("txtQval" + local_filter_index.ToString(), true)[0]);

            Label lblFreq = (Label)(Controls.Find("lblFreq" + local_filter_index.ToString(), true)[0]);
            Label lblGain = (Label)(Controls.Find("lblGain" + local_filter_index.ToString(), true)[0]);
            Label lblQ = (Label)(Controls.Find("lblQ" + local_filter_index.ToString(), true)[0]);
            Label lblSlope = (Label)(Controls.Find("lblSlope" + local_filter_index.ToString(), true)[0]);

            Label lblFilterSelector = (Label)(Controls.Find("lblFilterSelector" + local_filter_index.ToString(), true)[0]);

            filterSelector.Visible = true;

            BandPassFilter toolFilter = new BandPassFilter(0, 0, 0);

            switch (((ComboBox)sender).SelectedIndex)
            {
                case LOW_PASS:

                    if (graph_loaded)
                    {
                        if (dropSlope.SelectedIndex == 0)
                        {
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.FirstOrderLowPass, bypass_value);
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new FirstOrderLowPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));
                        }
                        else
                        {
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.SecondOrderLowPass, bypass_value);
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new SecondOrderLowPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));
                        }
                    }
                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = false;
                    txtGain.Visible = false;

                    lblQ.Visible = false;
                    txtQval.Visible = false;

                    lblSlope.Visible = true;
                    dropSlope.Visible = true;

                    if (graph_loaded)
                    {
                        dropSlope.SelectedIndex = 0;
                        dropSlope.Invalidate();
                    }

                    break;

                case HIGH_PASS:

                    if (graph_loaded)
                    {
                        if (dropSlope.SelectedIndex == 0)
                        {
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.FirstOrderHighPass, bypass_value);
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new FirstOrderHighPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));
                        }
                        else
                        {
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.SecondOrderHighPass, bypass_value);
                            PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new SecondOrderHighPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));
                        }
                    }

                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = false;
                    txtGain.Visible = false;

                    lblQ.Visible = false;
                    txtQval.Visible = false;

                    lblSlope.Visible = true;
                    dropSlope.Visible = true;

                    if (graph_loaded)
                    {
                        dropSlope.SelectedIndex = 0;
                        dropSlope.Invalidate();
                    }

                    break;

                case LOW_SHELF:
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.LowShelf, bypass_value);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new LowShelfFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));

                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = true;
                    txtGain.Visible = true;

                    lblQ.Visible = true;
                    txtQval.Visible = true;

                    lblSlope.Visible = false;
                    dropSlope.Visible = false;

                    break;

                case HIGH_SHELF:
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.HighShelf, bypass_value);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new HighShelfFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));

                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = true;
                    txtGain.Visible = true;

                    lblQ.Visible = true;
                    txtQval.Visible = true;

                    lblSlope.Visible = false;
                    dropSlope.Visible = false;

                    break;

                case BANDPASS:
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.BandPass, bypass_value);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new BandPassFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));

                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = false;
                    txtGain.Visible = false;

                    lblQ.Visible = true;
                    txtQval.Visible = true;

                    lblSlope.Visible = false;
                    dropSlope.Visible = false;

                    break;

                case PEAK:
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.Peak, bypass_value);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new PeakFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));

                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = true;
                    txtGain.Visible = true;

                    lblQ.Visible = true;
                    txtQval.Visible = true;

                    lblSlope.Visible = false;
                    dropSlope.Visible = false;

                    break;

                case NOTCH:
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.Notch, bypass_value);
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index].Filter = new NotchFilter(toolFilter.SuggestedFrequency(txtFreq.Text), toolFilter.SuggestedGain(txtGain.Text), toolFilter.SuggestedQ(txtQval.Text));

                    filterChart.Series[local_filter_index].Enabled = true;

                    lblFreq.Visible = true;
                    txtFreq.Visible = true;

                    lblGain.Visible = false;
                    txtGain.Visible = false;

                    lblQ.Visible = true;
                    txtQval.Visible = true;

                    lblSlope.Visible = false;
                    dropSlope.Visible = false;

                    break;

                default:
                    PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][global_filter_index] = new FilterConfig(FilterType.None, bypass_value);

                    filterChart.Series[local_filter_index].Enabled = false;

                    lblFreq.Visible = false;
                    txtFreq.Visible = false;

                    lblGain.Visible = false;
                    txtGain.Visible = false;

                    lblQ.Visible = false;
                    txtQval.Visible = false;

                    lblSlope.Visible = false;
                    dropSlope.Visible = false;

                    filterSelector.Visible = false;

                    removing_filter = true;
                    break;

            }

            if (graph_loaded)
            {
                if (!removing_filter)
                {
                    active_global_filter_index = global_filter_index;
                }
                else
                {

                    for (int j = starting_filter; j < starting_filter + total_filters; j++)
                    {
                        if ((PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][j] != null))
                        {
                            if(PARENT_FORM.PROGRAMS[PARENT_FORM.CURRENT_PROGRAM].filters[CH_NUMBER - 1][j].Type != FilterType.None)
                            {
                                active_global_filter_index = j;
                                break;
                            }
                        }
                    }

                }
                UpdateActiveFilter();

                RefreshSingleFilter(global_filter_index);
                RefreshMasterFilter();

                if (graph_loaded)
                {
                    SendFilterToParent(global_filter_index);
                }
            }
        }