/// <summary> /// Form to manage the Color Organ functionality /// </summary> /// <param name="xmlData"></param> /// <param name="sequence"></param> public ColorOrgan(ref XmlNode xmlData, EventSequence sequence) { // save the reference to the xml data m_xmlData = xmlData; // save the list of bands we have available to us foreach (int frequency in m_frequencyArray) { FrequencyBand newBand = new FrequencyBand(frequency); m_mapOfFrequencyBands.Add(newBand.CenterFrequency, newBand); } // end build base frequency objects // record the sequence m_sequence = sequence; // go find out what the peaks and valleys are for this sound track analyzeSoundTrack(); // process xml data and set up any pre defined groups // mark the frequency bands that are a member of this color organ band XmlNodeList colorOrganBandNodes = xmlData.SelectNodes(m_xmlName_listOfColorOrganBands + "/*"); foreach (XmlNode xmlColorOrganBandNode in colorOrganBandNodes) { ColorOrganBand newBand = new ColorOrganBand(xmlColorOrganBandNode, m_mapOfFrequencyBands, m_sequence, this); m_mapOfColorOrganBands.Add(newBand.ID, newBand); } // end build color organ band list // did we get any groups? if (0 == m_mapOfColorOrganBands.Count) { createDefaultColorOrganBandSet(-1, 1); } // end create default color band } // ColorOrganForm
} // default Color Organ Band /// <summary> /// Create an instance of a color organ band. /// </summary> /// <param name="xmlData"></param> public ColorOrganBand(ColorOrganBand template) { Sequence = template.Sequence; Name = template.Name + " - Copy"; m_id = DateTime.Now.ToString("yyyyMMddHHmmssffffff", System.Globalization.CultureInfo.InvariantCulture); m_colorOrgan = template.m_colorOrgan; m_minBinVariableRange = template.m_minBinVariableRange; m_maxBinVariableRange = template.m_maxBinVariableRange; m_usePeakLevels = template.m_usePeakLevels; m_energySumAvg = template.m_energySumAvg; m_energyPeak = template.m_energyPeak; m_energyMin = template.m_energyMin; m_energyCount = template.m_energyCount; m_clearChannelsOnWrite = template.m_clearChannelsOnWrite; m_frequencyBands = template.m_frequencyBands; m_mapOfFrequencyBands = new Dictionary <string, ColorOrganFrequencyBand>(); foreach (var band in template.m_mapOfFrequencyBands) { m_mapOfFrequencyBands.Add(band.Key, new ColorOrganFrequencyBand(band.Value)); } // end copy frequency bands m_mapOfChannels = new Dictionary <string, ColorOrganChannel>(); foreach (var channel in template.m_mapOfChannels) { m_mapOfChannels.Add(channel.Key, new ColorOrganChannel(channel.Value)); } // end copy channels } // ColorOrganBand(template)
} // CreateBand /// <summary> /// Create a new band with the default data. /// </summary> internal ColorOrganBand CreateBand(ColorOrganBand template) { ColorOrganBand temp = new ColorOrganBand(template); // create at least one Color Band that encompases all of the frequency bands m_mapOfColorOrganBands.Add(temp.ID, temp); return(temp); } // CreateBand
} // ColorOrganForm /// <summary> /// Add a new band to the list of bands and open a dialog for it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonNewColorGroup_Click(object sender, EventArgs e) { ColorOrganBand band = m_colorOrgan.CreateBand(); populateColorOrganBandSelectList(); ColorOrganForm temp = this; ColorOrganBandForm cobf = new ColorOrganBandForm(ref band, ref temp); cobf.Show(); } // buttonNewColorGroup_Click
} // buttonEditColorGroup_Click /// <summary> /// Remove a band from the list of bands /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonDeleteColorGroup_Click(object sender, EventArgs e) { // are there any bands to delete? if (0 < m_mapOfColorOrganBands.Count) { // get the band to be deleted ColorOrganBand band = m_mapOfColorOrganBands[listBoxColorBands.SelectedIndex]; // tell the color organ to delete the band m_colorOrgan.DeleteBand(band.ID); // update the display list populateColorOrganBandSelectList(); } } // buttonDeleteColorGroup_Click
} // buttonNewColorGroup_Click /// <summary> /// User has pressed edit or double clicked an entry in the table /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonEditColorGroup_Click(object sender, EventArgs e) { do { // are there any bands to edit? if (0 == m_mapOfColorOrganBands.Count) { break; } // end no bands to edit ColorOrganBand band = m_mapOfColorOrganBands[listBoxColorBands.SelectedIndex]; ColorOrganForm temp = this; ColorOrganBandForm cobf = new ColorOrganBandForm(ref band, ref temp); cobf.Show(); } while (false); } // buttonEditColorGroup_Click
public ColorOrganBandForm(ref ColorOrganBand colorOrganBand, ref ColorOrganForm parentForm) { InitializeComponent(); // save the reference to this band m_colorOrganBand = colorOrganBand; m_parentForm = parentForm; // set up the table grid dataGridViewFrequencyBands.CellValueChanged -= dataGridViewFrequencyBands_CellValueChanged; dataGridViewFrequencyBands.AllowUserToOrderColumns = false; dataGridViewFrequencyBands.AllowUserToAddRows = false; dataGridViewFrequencyBands.AllowUserToDeleteRows = false; dataGridViewFrequencyBands.Enabled = true; dataGridViewFrequencyBands.CellValueChanged += dataGridViewFrequencyBands_CellValueChanged; } // ColorOrganBandForm
} // buttonClearChannels_Click /// <summary> /// user has requested that we make a copy of the current band /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonCopy_Click(object sender, EventArgs e) { do { // are there any bands to copy? if (0 == m_mapOfColorOrganBands.Count) { break; } // end no bands to copy ColorOrganBand destinationBand = m_colorOrgan.CreateBand(m_mapOfColorOrganBands[listBoxColorBands.SelectedIndex]); // copy to body of the data populateColorOrganBandSelectList(); ColorOrganForm temp = this; ColorOrganBandForm cobf = new ColorOrganBandForm(ref destinationBand, ref temp); cobf.Show(); } while (false); } // buttonCopy_Click
} // ClearChans /// <summary> /// Create a default set of color organ bands /// </summary> /// <param name="firstChanNumber">-1 means no channels assigned</param> /// <param name="numChans"></param> internal void createDefaultColorOrganBandSet(Int32 firstChanNumber, Int32 numChans) { ColorOrganBand band = null; Double frequencyStepPerBand = 31.0 / numChans; Double currentFrequencyStep = 0.0; Double currentFrequencyBand = 0.0; do { if (((firstChanNumber + numChans) > m_sequence.ChannelCount) && (-1 != firstChanNumber)) { MessageBox.Show("Too many channels requested. The number of outputs is greater than the number of channels available above the starting channel", "ERROR"); break; } if (numChans > (m_frequencyArray.Length)) { MessageBox.Show("Too many channels requested. The number of outputs is greater than the number of available frequencies", "ERROR"); break; } // clear the existing channels m_mapOfColorOrganBands.Clear(); // create the needed channels for (int chanCount = 0; chanCount < numChans; chanCount++) { band = new ColorOrganBand(m_mapOfFrequencyBands, m_sequence, this, false); // This is a bit of a hack: prevent duplicates due to going too fast while (true == m_mapOfColorOrganBands.ContainsKey(band.ID)) { band = new ColorOrganBand(m_mapOfFrequencyBands, m_sequence, this, false); } // set the band name band.Name = m_frequencyArray[Convert.ToInt32(currentFrequencyBand)].ToString(); // adjust the top of this band currentFrequencyBand += frequencyStepPerBand; // add frequencies while ((currentFrequencyBand > currentFrequencyStep) && (31 > currentFrequencyStep)) { // set the frequency to an active state band.SelectFrequency(m_frequencyArray[Convert.ToInt32(currentFrequencyStep)]); // advance to the next step currentFrequencyStep += 1.0; } // end add frequencies // set the trigger limits band.minBinVariableRange = Convert.ToSingle(band.Avg * 0.1); band.maxBinVariableRange = Convert.ToSingle((((band.Peak - band.Avg) / 4) * 3) + band.Avg); // make sure the channels get cleared before each write operation band.clearChannelsOnWrite = true; // do we need to activate an output channel for this band? if (-1 != firstChanNumber) { int chanNum = (firstChanNumber + chanCount) - 1; #if VIXEN_VERSION_2_5 ulong chanId = m_sequence.Channels[chanNum].ID; #else ulong chanId = Convert.ToUInt64(m_sequence.Channels[chanNum].GetHashCode()); #endif band.selectChannel(chanId); m_sequence.Channels[chanNum].Name = "CO: " + band.Name; // set up some inter channel color contrast m_sequence.Channels[chanNum].Color = (0 == (chanCount & 0x01)) ? System.Drawing.Color.White : System.Drawing.Color.LightBlue; } // end need to turn on a channel // add the new band to the list of bands m_mapOfColorOrganBands.Add(band.ID, band); } // end generate bands } while (false); } // createDefaultSet