Example #1
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     if (e.Button == MouseButtons.Left)
     {
         if (!isClickingPitchBar && hoveredPitchBar != null)
         {
             hoveredPitchBar.MouseDown(e);
             isClickingPitchBar = true;
         }
         else // not hovering pitchbar
         {
             if (!isCreatingPitchBar)
             {
                 isCreatingPitchBar = true;
                 createPitchBarFirstClick = e.X;
                 pitchBarInCreation = new PitchBar();
                 pitchBarInCreation.StartTime = hoveredTimeline;
                 pitchBarInCreation.NoteIndex = hoveredNote;
                 pitchBarInCreation.Left = e.X;
                 pitchBarInCreation.Top = ((e.Y + offsetYToNextNoteIndex) / Program.GRID_VERTICAL * Program.GRID_VERTICAL) - offsetYToNextNoteIndex;
                 pitchBarInCreation.Click += new PitchBar.ClickHandler(pitchBarInCreation_Click);
                 pitchBarInCreation.Resizing += new PitchBar.ResizingHandler(pitchBarInCreation_Resizing);
             }
         }
     }
     else if (e.Button == MouseButtons.Right)
         contextMenuStrip.Show(this, e.Location);
 }
Example #2
0
 public static void ResizeToNeighbour(List<PitchBar> listPitchBar, PitchBar newPitchBar)
 {
     int index = listPitchBar.IndexOf(newPitchBar);
     bool isNeedResize = false;
     // check left
     if (index - 1 >= 0)
     {
         PitchBar leftPitchBar = listPitchBar[index - 1];
         if (newPitchBar.StartTime < leftPitchBar.EndTime)
         {
             newPitchBar.StartTime = leftPitchBar.EndTime;
             newPitchBar.Left = leftPitchBar.Left + leftPitchBar.Width;
             isNeedResize = true;
         }
     }
     // check right
     if (index + 1 < listPitchBar.Count)
     {
         PitchBar rightPitchBar = listPitchBar[index + 1];
         if (newPitchBar.EndTime > rightPitchBar.StartTime)
         {
             newPitchBar.EndTime = rightPitchBar.StartTime;
             isNeedResize = true;
         }
     }
     // check need to resize
     if (isNeedResize)
         newPitchBar.ResizeAccordingToPixelPerSecond();
 }
Example #3
0
 // note the singular
 public void RelocatePitchBar(PitchBar pitchBar)
 {
     pitchBar.Left = (int)((pitchBar.StartTime - LeftMostTime) * Program.PixelPerSecond);
     pitchBar.Top = ((Program.RegisteredNotes.Count - 1 - pitchBar.NoteIndex - TopMostNoteIndex) * Program.GRID_VERTICAL) - offsetYToNextNoteIndex;
 }
Example #4
0
 public static List<PitchBar> GetPitchBarsInSentences(List<PitchBar> listPitchBar, PitchBar pitchBar)
 {
     int indexDecreement = listPitchBar.IndexOf(pitchBar) - 1;
     bool isFound = false;
     while (!isFound && indexDecreement >= 0)
     {
         isFound = listPitchBar[indexDecreement].IsLastWord;
         if (!isFound)
             indexDecreement--;
     }
     if (indexDecreement < 0)
         indexDecreement = 0;
     else
         indexDecreement += 1;
     int indexIncreement = listPitchBar.IndexOf(pitchBar);
     isFound = false;
     while (!isFound && indexIncreement < listPitchBar.Count)
     {
         isFound = listPitchBar[indexIncreement].IsLastWord;
         if (!isFound)
             indexIncreement++;
     }
     if (indexIncreement >= listPitchBar.Count)
         indexIncreement = listPitchBar.Count - 1;
     return listPitchBar.GetRange(indexDecreement, indexIncreement - indexDecreement + 1);
 }
Example #5
0
 //
 // static methods
 //
 public static void InsertSorted(List<PitchBar> listPitchBar, PitchBar newPitchBar)
 {
     int index = 0;
     if (listPitchBar != null)
     {
         while (index < listPitchBar.Count && listPitchBar[index].StartTime < newPitchBar.StartTime)
             index++;
         listPitchBar.Insert(index, newPitchBar);
     }
 }
Example #6
0
 private void SearchNextPitchBarToPlay(double time)
 {
     int i = 0;
     bool isFound = false;
     while (!isFound && i < Program.PitchBars.Count)
     {
         if (Program.PitchBars[i].StartTime > time)
             isFound = true;
         else
             i++;
         if (i < Program.PitchBars.Count)
             nextPitchBarToPlay = Program.PitchBars[i];
         else
             nextPitchBarToPlay = null;
     }
 }
Example #7
0
 private void UpdatePropertyPanel(PitchBar selectedPitchBar)
 {
     if (selectedPitchBar == null)
     {
         textBoxStartTime.Text = "";
         textBoxLength.Text = "";
         textBoxLyric.Text = "";
         comboBoxNoteIndex.SelectedIndex = 0;
         textBoxEndTime.Text = "";
         checkBoxIsEnd.Checked = false;
         UpdateStatus("None Selected");
     }
     else
     {
         textBoxStartTime.Text = Program.DoubleToTimespanString(selectedPitchBar.StartTime);
         textBoxLength.Text = Program.DoubleToTimespanString(selectedPitchBar.Length);
         textBoxLyric.Text = selectedPitchBar.Lyric;
         comboBoxNoteIndex.SelectedIndex = Program.PANEL_PIANO_NOTE_COUNT - selectedPitchBar.NoteIndex + Program.PANEL_PIANO_START_NOTE_INDEX - 1;
         textBoxEndTime.Text = Program.DoubleToTimespanString(selectedPitchBar.EndTime);
         checkBoxIsEnd.Checked = selectedPitchBar.IsLastWord;
         UpdateStatus("Selected: " + Program.RegisteredNotes[selectedPitchBar.NoteIndex]);
     }
 }
Example #8
0
        private void CheckIsUICompatible(PitchBar pitchBar)
        {
            List<double> durationList;

            durationList = Program.ProcessSentenceDuration(ucEditor.PitchBars);

            if (Program.SentenceCount != durationList.Count)
            {
                if (durationList[pitchBar.GroupIndex] > 8)
                {
                    MessageBox.Show(
                        "Sentence's total duration exceeds maximum duration threshold (" + 8 + " sec)"// +
                        //", or Sentence's total character width exceed " + Program.MAXIMUM_CHARACTER_WIDTH_IN_SENTENCE + " pixels." +
                        //"\n" + "Character width: " + lyricWidth + " pixels, Sentence: " + lyric[0] + "." + "\n" +
                        //"Total duration: " + totalDuration + " secs (" + Program.DoubleToTimespanString(startSentencePoint) + " - " + Program.DoubleToTimespanString(endSentencePoint) + ")."
                        , "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            Program.SentenceCount = durationList.Count;

            durationList.Clear();
        }
Example #9
0
 private void ucEditor_SelectedPitchBarChanging(object sender, PitchBar oldPitchBar, PitchBar newPitchBar)
 {
     if (Program.IsAutoApply && oldPitchBar != null)
         ApplyPropertyPanel(oldPitchBar);
     UpdatePropertyPanel(newPitchBar);
     textBoxLyric.Focus();
     listBoxBarnodes.SelectedIndex = ucEditor.PitchBars.IndexOf(newPitchBar);
     UpdateStatus("");
 }
Example #10
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (isDoneParse)
            {
                sequencer.Stop();
                int vocalTrackNumber = (int)numericUpDownVocal.Value - 1;
                int lyricTrackNumber = (int)numericUpDownLyric.Value - 1;
                if (vocalTrackNumber >= 0 && vocalTrackNumber < sequence.Count && lyricTrackNumber >= 0 && lyricTrackNumber < sequence.Count)
                {
                    List<MidiEvent> vocalMidiEvents = sequence[vocalTrackNumber].Iterator().ToList();
                    List<MidiEvent> lyricMidiEvents = textMidiEvents[lyricTrackNumber];
                    Pitchbars = new List<PitchBar>();
                    PitchBar lastPitchBar = null;
                    double currentTime = 0;
                    double currentLyricTime = 0;
                    bool foundLyric = false;
                    MidiEvent lyricMidiEvent = null;
                    int midiEventLyricIndex = -1;
                    double tickMultiplier = tempo / 1000000 / sequence.Division;

                    for (int i = 0; i < vocalMidiEvents.Count; i++)
                    {
                        MidiEvent midiEvent = vocalMidiEvents[i];
                        currentTime = midiEvent.AbsoluteTicks * tickMultiplier;
                        bool isLyricFound = currentTime <= currentLyricTime;
                        foundLyric = (currentTime == currentLyricTime);

                        while (!isLyricFound)
                        {
                            midiEventLyricIndex += 1;
                            if (midiEventLyricIndex < lyricMidiEvents.Count)
                            {
                                lyricMidiEvent = lyricMidiEvents[midiEventLyricIndex];
                                currentLyricTime = lyricMidiEvent.AbsoluteTicks * tickMultiplier;
                                isLyricFound = currentTime <= currentLyricTime;
                                foundLyric = (currentTime == currentLyricTime);
                            }
                            else
                            {
                                foundLyric = false;
                                lyricMidiEvent = null;
                                isLyricFound = true;
                            }
                        }

                        if (midiEvent.MidiMessage.MessageType == MessageType.Channel)
                        {
                            ChannelMessage channelMessage = midiEvent.MidiMessage as ChannelMessage;
                            int noteIndex = channelMessage.Data1 + Program.MIDI_OFFSET;
                            int volume = channelMessage.Data2;
                            if ((channelMessage.Command == ChannelCommand.NoteOn && volume == 0) || channelMessage.Command == ChannelCommand.NoteOff) // note off
                            {
                                if (lastPitchBar != null && lastPitchBar.NoteIndex == noteIndex)
                                    lastPitchBar.EndTime = currentTime;
                            }
                            else if (channelMessage.Command == ChannelCommand.NoteOn && volume > 0 && noteIndex >= Program.PANEL_PIANO_START_NOTE_INDEX + Program.MIDI_OFFSET && noteIndex < Program.PANEL_PIANO_START_NOTE_INDEX + Program.PANEL_PIANO_NOTE_COUNT) // note on
                            {
                                PitchBar newPitchBar = new PitchBar();
                                newPitchBar.StartTime = currentTime;
                                newPitchBar.NoteIndex = noteIndex;
                                if (foundLyric && lyricMidiEvent != null && midiEventLyricIndex < textMidiData[lyricTrackNumber].Count)
                                {
                                    newPitchBar.Lyric = textMidiData[lyricTrackNumber][midiEventLyricIndex];
                                    if (lastPitchBar != null)
                                        lastPitchBar.IsLastWord = newPitchBar.Lyric.StartsWith(char.ConvertFromUtf32(47));
                                }
                                else
                                    newPitchBar.Lyric = "";
                                PitchBar.InsertSorted(Pitchbars, newPitchBar);
                                if (lastPitchBar != null)
                                    lastPitchBar.EndTime = currentTime;
                                lastPitchBar = newPitchBar;
                            }
                        }
                    //    if ((idolMidiEvent.CommandIdx == 9 && idolMidiEvent.Volume == 0) || idolMidiEvent.CommandIdx == 8) // note off
                    //    {
                    //        if (lastPitchBar != null && lastPitchBar.NoteIndex == idolMidiEvent.NoteIdx)
                    //            lastPitchBar.EndTime = currentTime;
                    //    }
                    //    else if (idolMidiEvent.CommandIdx == 9 && idolMidiEvent.Volume > 0 && idolMidiEvent.NoteIdx >= Program.PANEL_PIANO_START_NOTE_INDEX && idolMidiEvent.NoteIdx < Program.PANEL_PIANO_START_NOTE_INDEX + Program.PANEL_PIANO_NOTE_COUNT) // note on
                    //    {
                    //        PitchBar newPitchBar = new PitchBar();
                    //        newPitchBar.StartTime = currentTime;
                    //        newPitchBar.NoteIndex = idolMidiEvent.NoteIdx;
                    //        if (idolMIDIEventLyric != null && idolMIDIEventLyric.Metadata != null)
                    //        {
                    //            newPitchBar.Lyric = idolMIDIEventLyric.Metadata;
                    //            if (lastPitchBar != null)
                    //                lastPitchBar.IsLastWord = newPitchBar.Lyric.StartsWith(char.ConvertFromUtf32(47));
                    //        }
                    //        else
                    //            newPitchBar.Lyric = "";
                    //        PitchBar.InsertSorted(Pitchbars, newPitchBar);
                    //        if (lastPitchBar != null)
                    //            lastPitchBar.EndTime = currentTime;
                    //        lastPitchBar = newPitchBar;
                    //    }
                    }
                    DialogResult = DialogResult.OK;
                }
                else
                    MessageBox.Show("Number of selected tracks is / are invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #11
0
        private void ApplyPropertyPanel(PitchBar pitchBar)
        {
            if (pitchBar != null && ValidatePropertyPanel())
            {
                // apply properties
                pitchBar.StartTime = startTimeProperty;
                pitchBar.EndTime = endTimeProperty;
                pitchBar.NoteIndex = Program.RegisteredNotes.Count - 1 - comboBoxNoteIndex.SelectedIndex;
                pitchBar.Lyric = textBoxLyric.Text;
                pitchBar.IsLastWord = checkBoxIsEnd.Checked;
                pitchBar.ResizeAccordingToPixelPerSecond();

                Program.ProcessGroupAndWordIndex(ucEditor.PitchBars);
                CheckIsUICompatible(pitchBar);
                ucEditor.RefreshScreen();
                UpdateStatus("Property Applied");
                currencyManager.Refresh();
                SaveManager.isDirty = true;

                // check UI compatible
                if (pitchBar.Lyric != null && pitchBar.Lyric != "")
                {
                    //CheckIsUICompatible();
                    //List<PitchBar> pitchBarInSentence = PitchBar.GetPitchBarsInSentences(ucEditor.PitchBars, pitchBar);
                    //CheckIsUICompatible(pitchBarInSentence);
                }
            }
        }
Example #12
0
 public static List<PitchBar> NotesToPitchBars(List<Note> notes)
 {
     List<PitchBar> result = new List<PitchBar>();
     for (int i = 0; i < notes.Count; i++)
     {
         PitchBar newPitchBar = new PitchBar();
         newPitchBar.StartTime = notes[i].StartPoint;
         newPitchBar.EndTime = notes[i].EndPoint;
         newPitchBar.NoteIndex = notes[i].NoteIndex;
         result.Add(newPitchBar);
     }
     return result;
 }
Example #13
0
        private static string PitchBarToString(PitchBar pitchBars)
        {
            string result = "";
            result += ":";
            result += " " + (pitchBars.StartTime * 1000);
            result += " " + (pitchBars.EndTime * 1000);
            result += " " + pitchBars.NoteIndex;
            result += " " + pitchBars.WordIndex;
            result += " " + Program.CutDashIfExist(pitchBars.Lyric, false);

            return result;
        }
Example #14
0
        private static PitchBar ParseToPitchBar(string[] input)
        {
            PitchBar result = new PitchBar();

            result.StartTime = double.Parse(input[1]) / 1000;
            result.EndTime = double.Parse(input[2]) / 1000;
            result.NoteIndex = int.Parse(input[3]);
            result.GroupIndex = currentGroupNo;
            result.WordIndex = int.Parse(input[4]);
            result.Lyric = input[5];

            return result;
        }
Example #15
0
 private void CheckHover(MouseEventArgs e)
 {
     bool isHoveringPitchBar = false;
     int pitchBarIndex = 0;
     while (!isHoveringPitchBar && pitchBarIndex < PitchBars.Count)
     {
         if (PitchBars[pitchBarIndex].IsInsideBound(LeftMostTime, RightMostTime))
         {
             isHoveringPitchBar = PitchBars[pitchBarIndex].IsHovered(e.X, e.Y);
         }
         if (!isHoveringPitchBar)
             pitchBarIndex++;
     }
     if (isHoveringPitchBar)
     {
         hoveredPitchBar = PitchBars[pitchBarIndex];
     }
     else
         hoveredPitchBar = null;
 }
Example #16
0
 private void ucEditor_SelectedPitchBarUpdating(object sender, PitchBar newPitchBar)
 {
     UpdatePropertyPanel(newPitchBar);
     textBoxLyric.Focus();
     currencyManager.Refresh();
 }
Example #17
0
 private void InitializeObjects()
 {
     isCreatingPitchBar = false;
     isClickingPitchBar = false;
     ChangeSize();
     LastPitchBar = null;
     SelectedPitchBar = null;
     hoveredPitchBar = null;
     pitchBarInCreation = null;
     PitchBars = new List<PitchBar>();
     sequence.Clear();
     SetMIDITempo();
     pitchBarTrack = new Track();
     sequence.Add(pitchBarTrack);
     if (PitchbarChanged != null)
         PitchbarChanged(this, PitchBars);
 }
Example #18
0
 private void DelegateThreadWorker()
 {
     while (nextPitchBarToPlay != null)
     {
         if (nextPitchBarToPlay.StartTime <= currentTime)
         {
             int index = Program.PitchBars.IndexOf(nextPitchBarToPlay);
             if (index + 1 < Program.PitchBars.Count)
                 nextPitchBarToPlay = Program.PitchBars[index + 1];
             else
                 nextPitchBarToPlay = null;
         }
     }
 }