private void PasteCopiedNotes()
    {
        int      minBeat = CopiedNotes.Select(it => it.StartBeat).Min();
        Sentence sentenceAtBeatWithVoice = SongMetaUtils.GetSentencesAtBeat(songMeta, minBeat)
                                           .Where(it => it.Voice != null).FirstOrDefault();

        // Find voice to insert the notes into
        Voice voice;

        if (copiedVoice != null)
        {
            voice = copiedVoice;
        }
        else if (sentenceAtBeatWithVoice != null)
        {
            voice = sentenceAtBeatWithVoice.Voice;
        }
        else
        {
            voice = songMeta.GetVoices().FirstOrDefault();
        }

        // Add the notes to the voice
        foreach (Note note in CopiedNotes)
        {
            InsertNote(note, voice);
        }
        ClearCopiedNotes();

        songMetaChangeEventStream.OnNext(new NotesAddedEvent());
    }
    private void FillContextMenu(ContextMenuPopupControl contextMenu)
    {
        int beat     = (int)noteAreaControl.GetHorizontalMousePositionInBeats();
        int midiNote = noteAreaControl.GetVerticalMousePositionInMidiNote();

        contextMenu.AddItem("Fit vertical", () => noteAreaControl.FitViewportVerticalToNotes());

        Sentence sentenceAtBeat = SongMetaUtils.GetSentencesAtBeat(songMeta, beat).FirstOrDefault();

        if (sentenceAtBeat != null)
        {
            int minBeat = sentenceAtBeat.MinBeat - 1;
            int maxBeat = sentenceAtBeat.ExtendedMaxBeat + 1;
            contextMenu.AddItem("Fit horizontal to sentence ", () => noteAreaControl.FitViewportHorizontal(minBeat, maxBeat));
        }

        List <Note> selectedNotes = selectionControl.GetSelectedNotes();

        if (selectedNotes.Count > 0)
        {
            int minBeat = selectedNotes.Select(it => it.StartBeat).Min() - 1;
            int maxBeat = selectedNotes.Select(it => it.EndBeat).Max() + 1;
            contextMenu.AddItem("Fit horizontal to selection", () => noteAreaControl.FitViewportHorizontal(minBeat, maxBeat));
        }

        if (selectedNotes.Count > 0 ||
            songEditorCopyPasteManager.CopiedNotes.Count > 0)
        {
            contextMenu.AddSeparator();
            if (selectedNotes.Count > 0)
            {
                contextMenu.AddItem("Copy notes", () => songEditorCopyPasteManager.CopySelectedNotes());
            }

            if (songEditorCopyPasteManager.CopiedNotes.Count > 0)
            {
                contextMenu.AddItem("Paste notes", () => songEditorCopyPasteManager.PasteCopiedNotes());
            }
        }

        contextMenu.AddSeparator();
        contextMenu.AddItem("Add note", () => addNoteAction.ExecuteAndNotify(songMeta, beat, midiNote));

        if (selectedNotes.Count == 0)
        {
            contextMenu.AddSeparator();
            contextMenu.AddItem("Set Gap to playback position", () => setMusicGapAction.ExecuteAndNotify());
        }
    }
    private void InsertNote(Note note, Voice voice)
    {
        Sentence sentenceAtBeatOfVoice = SongMetaUtils.GetSentencesAtBeat(songMeta, note.StartBeat)
                                         .Where(sentence => sentence.Voice == voice).FirstOrDefault();

        if (sentenceAtBeatOfVoice == null)
        {
            // Add sentence with note
            Sentence newSentence = new Sentence(new List <Note> {
                note
            }, note.EndBeat);
            newSentence.SetVoice(voice);
        }
        else
        {
            // Add note to existing sentence
            note.SetSentence(sentenceAtBeatOfVoice);
        }
    }
Exemple #4
0
    public void Execute(SongMeta songMeta, int beat, int midiNote)
    {
        List <Sentence> sentencesAtBeat = SongMetaUtils.GetSentencesAtBeat(songMeta, beat);

        if (sentencesAtBeat.Count == 0)
        {
            // Add sentence with note
            Note newNote = new Note(ENoteType.Normal, beat - 2, 4, 0, "~");
            newNote.SetMidiNote(midiNote);
            Sentence newSentence = new Sentence(new List <Note> {
                newNote
            }, newNote.EndBeat);
            IReadOnlyCollection <Voice> voices = songMeta.GetVoices();
            newSentence.SetVoice(voices.FirstOrDefault());
        }
        else
        {
            // Add note to existing sentence
            Note newNote = new Note(ENoteType.Normal, beat - 2, 4, 0, "~");
            newNote.SetMidiNote(midiNote);
            newNote.SetSentence(sentencesAtBeat[0]);
        }
    }