Exemplo n.º 1
0
        public static List <UNote> WriteNotes(UProject project, UVoicePart part, IEnumerable <UNote> notes, string filePath)
        {
            List <UNote> sequence = new List <UNote>();

            using (var writer = new StreamWriter(filePath, false, ShiftJIS)) {
                WriteHeader(project, part, writer);
                int position = 0;
                foreach (var note in notes)
                {
                    if (note.position != position)
                    {
                        writer.WriteLine($"[#{sequence.Count:D4}]");
                        var spacer = UNote.Create();
                        spacer.position = position;
                        spacer.duration = note.position - position;
                        spacer.lyric    = "R";
                        spacer.tone     = 60;
                        sequence.Add(spacer);
                        WriteNoteBody(project, spacer, writer);
                    }
                    writer.WriteLine($"[#{sequence.Count:D4}]");
                    WriteNoteBody(project, note, writer);
                    position = note.End;
                    sequence.Add(note);
                }
                WriteFooter(writer);
            }
            return(sequence);
        }
Exemplo n.º 2
0
        public override void Redraw(DrawingContext cxt)
        {
            if (Part != null)
            {
                bool  inView, lastInView = false;
                UNote lastNote = null;
                foreach (var note in Part.Notes)
                {
                    inView = midiVM.NoteIsInView(note);

                    if (inView && !lastInView)
                    {
                        if (lastNote != null)
                        {
                            DrawNote(lastNote, cxt);
                        }
                    }

                    if (inView || !inView && lastInView)
                    {
                        DrawNote(note, cxt);
                    }

                    lastNote   = note;
                    lastInView = inView;
                }
            }
        }
Exemplo n.º 3
0
 public MoveNoteCommand(UVoicePart part, UNote note, int deltaPos, int deltaNoteNum)
 {
     this.Part         = part;
     this.Notes        = new UNote[] { note };
     this.DeltaPos     = deltaPos;
     this.DeltaNoteNum = deltaNoteNum;
 }
Exemplo n.º 4
0
        private void DrawNoteBody(UNote note, DrawingContext cxt)
        {
            Point leftTop = PosToPoint(new Vector2(note.position, note.tone));

            leftTop.X += 1;
            leftTop.Y += 1;
            Point rightBottom = PosToPoint(new Vector2(note.position + note.duration, note.tone - 1));

            rightBottom.Y -= 1;
            Size size = new Size(Math.Max(1, rightBottom.X - leftTop.X), Math.Max(1, rightBottom.Y - leftTop.Y));

            cxt.DrawRoundedRectangle(GetNoteBrush(note), null, new Rect(leftTop, rightBottom), 2, 2);
            if (size.Height < 10 || note.lyric.Length == 0)
            {
                return;
            }
            string displayLyric = note.lyric;
            var    fTextItem    = GetFormattedText(displayLyric, true);

            if (fTextItem.width + 5 > size.Width)
            {
                displayLyric = note.lyric[0] + "..";
                fTextItem    = GetFormattedText(displayLyric, true);
                if (fTextItem.width + 5 > size.Width)
                {
                    return;
                }
            }
            cxt.DrawText(fTextItem.fText, new Point((int)leftTop.X + 5, Math.Round(leftTop.Y + (size.Height - fTextItem.height) / 2)));
        }
Exemplo n.º 5
0
 public ChangeNoteLyricCommand(UVoicePart part, UNote note, string newLyric)
 {
     Part     = part;
     Note     = note;
     NewLyric = newLyric;
     OldLyric = note.Lyric;
 }
Exemplo n.º 6
0
 public PhonemeChangeOverlapState(Canvas canvas, PianoRollViewModel vm,
                                  UNote leadingNote, UPhoneme phoneme, int index) : base(canvas, vm)
 {
     this.leadingNote = leadingNote;
     this.phoneme     = phoneme;
     this.index       = index;
 }
Exemplo n.º 7
0
        private void DrawVibratoControl(UNote note, DrawingContext cxt)
        {
            var vibrato = note.vibrato;

            if (vibrato.length == 0)
            {
                return;
            }
            Point start   = PosToPoint(vibrato.GetEnvelopeStart(note));
            Point fadeIn  = PosToPoint(vibrato.GetEnvelopeFadeIn(note));
            Point fadeOut = PosToPoint(vibrato.GetEnvelopeFadeOut(note));
            Point end     = PosToPoint(vibrato.GetEnvelopeEnd(note));

            cxt.DrawLine(penVbr, start, fadeIn);
            cxt.DrawLine(penVbr, fadeIn, fadeOut);
            cxt.DrawLine(penVbr, fadeOut, end);
            cxt.DrawEllipse(penVbr.Brush, penVbr, start, 2.5, 2.5);
            cxt.DrawEllipse(penVbr.Brush, penVbr, fadeIn, 2.5, 2.5);
            cxt.DrawEllipse(penVbr.Brush, penVbr, fadeOut, 2.5, 2.5);
            vibrato.GetPeriodStartEnd(note, DocManager.Inst.Project, out var periodStartPos, out var periodEndPos);
            Point periodStart = PosToPoint(periodStartPos);
            Point periodEnd   = PosToPoint(periodEndPos);
            float height      = (float)TrackHeight / 3;

            periodStart.Y -= height / 2 + 0.5f;
            double width = periodEnd.X - periodStart.X;

            periodEnd.X -= 2;
            periodEnd.Y -= height / 2 + 0.5f;
            cxt.DrawRoundedRectangle(null, penVbr, new Rect(periodStart, new Size(width, height)), 1, 1);
            cxt.DrawLine(penVbr, periodEnd, periodEnd + new System.Windows.Vector(0, height));
        }
Exemplo n.º 8
0
 public DeletePitchPointCommand(UVoicePart part, UNote note, int index)
 {
     this.Part  = part;
     this.Note  = note;
     this.Index = index;
     this.Point = Note.pitch.data[Index];
 }
Exemplo n.º 9
0
        private void DrawPitchBend(UNote note, DrawingContext cxt)
        {
            var _pitchExp = note.PitchBend as PitchBendExpression;
            var _pts      = _pitchExp.Data as List <PitchPoint>;

            if (_pts.Count < 2)
            {
                return;
            }

            double pt0Tick = note.PosTick + MusicMath.MillisecondToTick(_pts[0].X, DocManager.Inst.Project.BPM, DocManager.Inst.Project.BeatUnit, DocManager.Inst.Project.Resolution);
            double pt0X    = midiVM.QuarterWidth * pt0Tick / DocManager.Inst.Project.Resolution;
            double pt0Pit  = note.NoteNum + _pts[0].Y / 10.0;
            double pt0Y    = TrackHeight * ((double)UIConstants.MaxNoteNum - 1.0 - pt0Pit) + TrackHeight / 2;

            if (note.PitchBend.SnapFirst)
            {
                cxt.DrawEllipse(ThemeManager.WhiteKeyNameBrushNormal, penPit, new Point(pt0X, pt0Y), 2.5, 2.5);
            }
            else
            {
                cxt.DrawEllipse(null, penPit, new Point(pt0X, pt0Y), 2.5, 2.5);
            }

            for (int i = 1; i < _pts.Count; i++)
            {
                double pt1Tick = note.PosTick + MusicMath.MillisecondToTick(_pts[i].X, DocManager.Inst.Project.BPM, DocManager.Inst.Project.BeatUnit, DocManager.Inst.Project.Resolution);
                double pt1X    = midiVM.QuarterWidth * pt1Tick / DocManager.Inst.Project.Resolution;
                double pt1Pit  = note.NoteNum + _pts[i].Y / 10.0;
                double pt1Y    = TrackHeight * ((double)UIConstants.MaxNoteNum - 1.0 - pt1Pit) + TrackHeight / 2;

                // Draw arc
                double _x  = pt0X;
                double _x2 = pt0X;
                double _y  = pt0Y;
                double _y2 = pt0Y;
                if (pt1X - pt0X < 5)
                {
                    cxt.DrawLine(penPit, new Point(pt0X, pt0Y), new Point(pt1X, pt1Y));
                }
                else
                {
                    while (_x2 < pt1X)
                    {
                        _x = Math.Min(_x + 4, pt1X);
                        _y = MusicMath.InterpolateShape(pt0X, pt1X, pt0Y, pt1Y, _x, _pts[i - 1].Shape);
                        cxt.DrawLine(penPit, new Point(_x, _y), new Point(_x2, _y2));
                        _x2 = _x;
                        _y2 = _y;
                    }
                }

                pt0Tick = pt1Tick;
                pt0X    = pt1X;
                pt0Pit  = pt1Pit;
                pt0Y    = pt1Y;
                cxt.DrawEllipse(null, penPit, new Point(pt0X, pt0Y), 2.5, 2.5);
            }
        }
Exemplo n.º 10
0
 public SetIntExpCommand(UVoicePart part, UNote note, string key, int newValue)
 {
     this.Part     = part;
     this.Note     = note;
     this.Key      = key;
     this.NewValue = newValue;
     this.OldValue = (int)Note.Expressions[Key].Data;
 }
Exemplo n.º 11
0
    //--------------------------------------------------------------------------------------------

    #region Hinventory CALLBACKS
    static void OnNoteAdded(int _instanceID, UNote _note)
    {
        Debug.Log("OnNoteAdded");
        instance.getAndSortNotes(); // done as late initialization
        instance.Repaint();

        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
    }
Exemplo n.º 12
0
    // _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

    #region Editor Utilities

    public static void SelectObjectWithNote(UNote _note)
    {
        if (collection.ContainsValue(_note))
        {
            int __instanceID = collection.FirstOrDefault(x => x.Value == _note).Key;
            Selection.activeInstanceID = __instanceID;
        }
    }
Exemplo n.º 13
0
        public void ToggleVibrato(UNote note)
        {
            var vibrato = note.vibrato;

            DocManager.Inst.StartUndoGroup();
            DocManager.Inst.ExecuteCmd(new VibratoLengthCommand(Part, note, vibrato.length == 0 ? 75f : 0));
            DocManager.Inst.EndUndoGroup();
        }
Exemplo n.º 14
0
 private static void ParseLyric(UNote note, string ust)
 {
     if (ust.StartsWith("?"))
     {
         ust = ust.Substring(1);
     }
     note.lyric = ust;
 }
Exemplo n.º 15
0
        private static void ParsePitchBend(UNote note, string pbs, string pbw, string pby, string pbm)
        {
            if (!string.IsNullOrWhiteSpace(pbs))
            {
                var points = note.PitchBend.Data as List <PitchPoint>;
                points.Clear();
                if (pbs.Contains(';'))
                {
                    points.Add(new PitchPoint(double.Parse(pbs.Split(new[] { ';' })[0]), double.Parse(pbs.Split(new[] { ';' })[1])));
                    note.PitchBend.SnapFirst = false;
                }
                else
                {
                    points.Add(new PitchPoint(double.Parse(pbs), 0));
                    note.PitchBend.SnapFirst = true;
                }
                var x = points.First().X;
                if (!string.IsNullOrWhiteSpace(pbw))
                {
                    var w = pbw.Split(',').Select(s => string.IsNullOrEmpty(s) ? 0 : double.Parse(s)).ToList();
                    var y = (pby ?? "").Split(',').Select(s => string.IsNullOrEmpty(s) ? 0 : double.Parse(s)).ToList();
                    while (w.Count > y.Count)
                    {
                        y.Add(0);
                    }
                    for (var i = 0; i < w.Count(); i++)
                    {
                        x += w[i];
                        points.Add(new PitchPoint(x, y[i]));
                    }
                }
                if (!string.IsNullOrWhiteSpace(pbm))
                {
                    var m = pbw.Split(new[] { ',' });
                    for (var i = 0; i < m.Count() - 1; i++)
                    {
                        switch (m[i])
                        {
                        case "r":
                            points[i].Shape = PitchPointShape.o;
                            break;

                        case "s":
                            points[i].Shape = PitchPointShape.l;
                            break;

                        case "j":
                            points[i].Shape = PitchPointShape.i;
                            break;

                        default:
                            points[i].Shape = PitchPointShape.io;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        private void DrawVibratoToggle(UNote note, DrawingContext cxt)
        {
            var   vibrato = note.vibrato;
            Point icon    = PosToPoint(vibrato.GetToggle(note));

            cxt.PushTransform(new TranslateTransform(icon.X - 10, icon.Y));
            cxt.DrawGeometry(vibrato.length == 0 ? null : penVbr.Brush, penVbr, vibratoIcon);
            cxt.Pop();
        }
Exemplo n.º 17
0
        public PhonemeOffsetCommand(UVoicePart part, UNote note, int index, int offset) : base(part, note)
        {
            this.note  = note;
            this.index = index;
            var o = this.note.GetPhonemeOverride(index);

            oldOffset = o.offset ?? 0;
            newOffset = offset;
        }
Exemplo n.º 18
0
        static void WriteVibrato(UNote note, StreamWriter writer)
        {
            var vbr = note.vibrato;

            if (vbr != null && vbr.length > 0)
            {
                writer.WriteLine($"VBR={vbr.length},{vbr.period},{vbr.depth},{vbr.@in},{vbr.@out},{vbr.shift},{vbr.drift}");
            }
        }
Exemplo n.º 19
0
        public PhonemeOverlapCommand(UVoicePart part, UNote note, int index, float scale) : base(part, note)
        {
            this.note  = note;
            this.index = index;
            var o = this.note.GetPhonemeOverride(index);

            oldScale = o.overlapScale ?? 1;
            newScale = scale;
        }
Exemplo n.º 20
0
        private static void ParsePitchBend(UNote note, string pbs, string pbw, string pby, string pbm)
        {
            if (!string.IsNullOrWhiteSpace(pbs))
            {
                var points = note.pitch.data;
                points.Clear();
                // PBS
                var   parts = pbs.Split(';');
                float pbsX  = parts.Length >= 1 && ParseFloat(parts[0], out pbsX) ? pbsX : 0;
                float pbsY  = parts.Length >= 2 && ParseFloat(parts[1], out pbsY) ? pbsY : 0;
                points.Add(new PitchPoint(pbsX, pbsY));
                note.pitch.snapFirst = false;
                // PBW, PBY
                var x = points.First().X;
                if (!string.IsNullOrWhiteSpace(pbw))
                {
                    var w = pbw.Split(',').Select(s => ParseFloat(s, out float v) ? v : 0).ToList();
                    var y = (pby ?? "").Split(',').Select(s => ParseFloat(s, out float v) ? v : 0).ToList();
                    while (w.Count > y.Count)
                    {
                        y.Add(0);
                    }
                    for (var i = 0; i < w.Count(); i++)
                    {
                        x += w[i];
                        points.Add(new PitchPoint(x, y[i]));
                    }
                }
                // PBM
                if (!string.IsNullOrWhiteSpace(pbm))
                {
                    var m = pbm.Split(new[] { ',' });
                    for (var i = 0; i < m.Count() && i < points.Count; i++)
                    {
                        switch (m[i])
                        {
                        case "r":
                            points[i].shape = PitchPointShape.o;
                            break;

                        case "s":
                            points[i].shape = PitchPointShape.l;
                            break;

                        case "j":
                            points[i].shape = PitchPointShape.i;
                            break;

                        default:
                            points[i].shape = PitchPointShape.io;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
    /// <summary>
    /// Removes the note.
    /// </summary>
    /// <param name="_instanceID">Instance I.</param>
    static void RemoveNote(int _instanceID)
    {
        UNote tmpNote = collection[_instanceID];

        collection.Remove(_instanceID);
        if (OnNoteRemoved != null)
        {
            OnNoteRemoved(_instanceID, tmpNote);
        }
    }
Exemplo n.º 22
0
        public NoteMoveEditState(Canvas canvas, PianoRollViewModel vm, UNote note) : base(canvas, vm)
        {
            this.note = note;
            var notesVm = vm.NotesViewModel;

            if (!notesVm.SelectedNotes.Contains(note))
            {
                notesVm.DeselectNotes();
            }
        }
Exemplo n.º 23
0
 private Brush GetNoteBrush(UNote note)
 {
     return(note.Error
         ? note.Selected
             ? ThemeManager.NoteFillSelectedErrorBrushes
             : ThemeManager.NoteFillErrorBrushes[0]
         : note.Selected
             ? ThemeManager.NoteFillSelectedBrush
             : ThemeManager.NoteFillBrushes[0]);
 }
Exemplo n.º 24
0
 private static void ParseLyric(UNote note, string ust)
 {
     if (ust.StartsWith("?"))
     {
         note.Phonemes[0].AutoRemapped = false;
         ust = ust.Substring(1);
     }
     note.Phonemes[0].Phoneme = ust;
     note.Lyric = ust;
 }
Exemplo n.º 25
0
 public void Show(UVoicePart part, UNote note, string text)
 {
     Part       = part;
     Note       = note;
     Visibility = Visibility.Visible;
     Text       = text;
     Focus();
     SelectAll();
     UpdateSuggestion();
 }
Exemplo n.º 26
0
    //--------------------------------------------------------------------------------------------

//    void createStyles()
//	{
//		styles = new GUIStyle[2];
//
////		// DEFAULT
//		styles [0] = new GUIStyle ();
//		styles [0].normal.background = whiteBgTex;
//		styles [0].fontSize = 12;
//		styles [0].padding = new RectOffset(8,8,7,8);
//
//		// ALTERNATIVE
//		styles [1] = new GUIStyle ();
//		styles [1].normal.background = whiteBgTex;
//        styles [1].normal.textColor = Color.black;
//		styles [1].fontSize = 11;
//		styles [1].padding = new RectOffset(8,8,7,8);
//		styles [1].fontStyle = FontStyle.Bold;
//	}

    GUIStyle CreateStyleForNote(UNote _note)
    {
        GUIStyle _style = new GUIStyle();

        _style.normal.background = whiteBgTex;
        _style.normal.textColor  = _note.color;
        _style.fontSize          = Mathf.Max(Mathf.Min(_note.fontSize, 15), 8);
        _style.padding           = new RectOffset(8, 8, 7, 8);
        _style.fontStyle         = FontStyle.Bold;
        return(_style);
    }
Exemplo n.º 27
0
        private void UpdateOverlapAdjustment(UVoicePart part)
        {
            UPhoneme lastPhoneme = null;
            UNote    lastNote    = null;

            foreach (UNote note in part.Notes)
            {
                foreach (UPhoneme phoneme in note.Phonemes)
                {
                    if (lastPhoneme != null)
                    {
                        int    gapTick = phoneme.Parent.PosTick + phoneme.PosTick - lastPhoneme.Parent.PosTick - lastPhoneme.EndTick;
                        double gapMs   = DocManager.Inst.Project.TickToMillisecond(gapTick);
                        if (gapMs < phoneme.Preutter)
                        {
                            phoneme.Overlapped = true;
                            double lastDurMs       = DocManager.Inst.Project.TickToMillisecond(lastPhoneme.DurTick);
                            double correctionRatio = (lastDurMs + Math.Min(0, gapMs)) / 2 / (phoneme.Preutter - phoneme.Overlap);
                            if (phoneme.Preutter - phoneme.Overlap > gapMs + lastDurMs / 2)
                            {
                                phoneme.OverlapCorrection = true;
                                phoneme.Preutter          = gapMs + (phoneme.Preutter - gapMs) * correctionRatio;
                                phoneme.Overlap          *= correctionRatio;
                            }
                            else if (phoneme.Preutter > gapMs + lastDurMs)
                            {
                                phoneme.OverlapCorrection = true;
                                phoneme.Overlap          *= correctionRatio;
                                phoneme.Preutter          = gapMs + lastDurMs;
                            }
                            else
                            {
                                phoneme.OverlapCorrection = false;
                            }

                            lastPhoneme.TailIntrude = phoneme.Preutter - gapMs;
                            lastPhoneme.TailOverlap = phoneme.Overlap;
                        }
                        else
                        {
                            phoneme.Overlapped      = false;
                            lastPhoneme.TailIntrude = 0;
                            lastPhoneme.TailOverlap = 0;
                        }
                    }
                    else
                    {
                        phoneme.Overlapped = false;
                    }
                    lastPhoneme = phoneme;
                }
                lastNote = note;
            }
        }
Exemplo n.º 28
0
 public PitchPointEditState(
     Canvas canvas, PianoRollViewModel vm, UNote note,
     int index, bool onPoint, float x, float y) : base(canvas, vm)
 {
     this.note    = note;
     this.index   = index;
     this.onPoint = onPoint;
     this.x       = x;
     this.y       = y;
     pitchPoint   = note.pitch.data[index];
 }
Exemplo n.º 29
0
 public void Show(UVoicePart part, UNote note, string text)
 {
     viewModel.Part      = part;
     viewModel.Note      = note;
     viewModel.Text      = text;
     viewModel.IsVisible = true;
     box.SelectAll();
     focusTimer       = new DispatcherTimer();
     focusTimer.Tick += FocusTimer_Tick;
     focusTimer.Start();
 }
Exemplo n.º 30
0
        private void DrawPitchBend(UNote note, DrawingContext cxt)
        {
            var _pitchExp = note.pitch;
            var _pts      = _pitchExp.data;

            if (_pts.Count < 2)
            {
                return;
            }

            double pt0Tick = note.position + MusicMath.MillisecondToTick(_pts[0].X, DocManager.Inst.Project.bpm, DocManager.Inst.Project.beatUnit, DocManager.Inst.Project.resolution);
            double pt0X    = midiVM.QuarterWidth * pt0Tick / DocManager.Inst.Project.resolution;
            double pt0Pit  = note.tone + _pts[0].Y / 10.0;
            double pt0Y    = TrackHeight * (UIConstants.MaxNoteNum - 1.0 - pt0Pit) + TrackHeight / 2;

            cxt.DrawEllipse(note.pitch.snapFirst ? penPit.Brush : null, penPit, new Point(pt0X, pt0Y), 2.5, 2.5);

            for (int i = 1; i < _pts.Count; i++)
            {
                double pt1Tick = note.position + MusicMath.MillisecondToTick(_pts[i].X, DocManager.Inst.Project.bpm, DocManager.Inst.Project.beatUnit, DocManager.Inst.Project.resolution);
                double pt1X    = midiVM.QuarterWidth * pt1Tick / DocManager.Inst.Project.resolution;
                double pt1Pit  = note.tone + _pts[i].Y / 10.0;
                double pt1Y    = TrackHeight * (UIConstants.MaxNoteNum - 1.0 - pt1Pit) + TrackHeight / 2;

                // Draw arc
                double _x  = pt0X;
                double _x2 = pt0X;
                double _y  = pt0Y;
                double _y2 = pt0Y;
                if (pt1X - pt0X < 5)
                {
                    cxt.DrawLine(penPit, new Point(pt0X, pt0Y), new Point(pt1X, pt1Y));
                }
                else
                {
                    while (_x2 < pt1X)
                    {
                        _x = Math.Min(_x + 4, pt1X);
                        _y = MusicMath.InterpolateShape(pt0X, pt1X, pt0Y, pt1Y, _x, _pts[i - 1].shape);
                        cxt.DrawLine(penPit, new Point(_x, _y), new Point(_x2, _y2));
                        _x2 = _x;
                        _y2 = _y;
                    }
                }

                pt0Tick = pt1Tick;
                pt0X    = pt1X;
                pt0Pit  = pt1Pit;
                pt0Y    = pt1Y;
                cxt.DrawEllipse(null, penPit, new Point(pt0X, pt0Y), 2.5, 2.5);
            }
        }