Пример #1
0
        public bool EditInternalNote(InternalNote oData)
        {
            methodName = "EditInternalNote";
            traceID    = 1;

            using (var uow = new UnitOfWork(AppConfig.Current.ContextName))
            {
                traceID = 2;
                var oDBData = uow.InternalNote.Get(oData.Id);
                if (oDBData != null)
                {
                    using (var trans = uow.BeginTransaction())
                    {
                        try
                        {
                            traceID = 3;
                            oDBData.MapFrom(oData);
                            uow.InternalNote.Update(oDBData);
                            uow.Save();

                            traceID = 4;
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            throw new AppException(500, methodName, traceID, ex);
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        public bool RemoveInternalNote(int id)
        {
            methodName = "RemoveInternalNote";
            traceID    = 1;

            using (var uow = new UnitOfWork(AppConfig.Current.ContextName))
            {
                using (var trans = uow.BeginTransaction())
                {
                    try
                    {
                        traceID = 2;
                        InternalNote oDBInternalNote = uow.InternalNote.SingleOrDefault(m => m.Id == id);
                        if (oDBInternalNote != null)
                        {
                            traceID = 3;
                            uow.InternalNote.Remove(id);
                            uow.Save();
                        }

                        traceID = 5;
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw new AppException(500, methodName, traceID, ex);
                    }
                }
            }

            return(true);
        }
Пример #3
0
        public static string ToString(InternalNote note, InternalNoteStringStyle style)
        {
            if (NoteUtils.IsNatural(note) || style != InternalNoteStringStyle.ShowBoth)
            {
                return(NoteUtils.ToString(NoteUtils.ToNote(note, style)));
            }
            else
            {
                switch (note)
                {
                case InternalNote.Cs_Db:
                    return("C#/Db");

                case InternalNote.Ds_Eb:
                    return("D#/Eb");

                case InternalNote.Fs_Gb:
                    return("F#/Gb");

                case InternalNote.Gs_Ab:
                    return("G#/Ab");

                case InternalNote.As_Bb:
                    return("A#/Bb");
                }
            }

            throw new ArgumentException();
        }
Пример #4
0
        public FullNote Shift(int steps, InternalNoteStringStyle style)
        {
            if (steps == 0)
            {
                return(new FullNote(NoteUtils.ToNote(InternalNote, style), Octave));
            }

            int direction = Math.Sign(steps);

            InternalNote note   = InternalNote;
            int          octave = Octave;

            for (int i = 0; i < steps; i++)
            {
                int noteIndex = (int)note + direction;
                if (noteIndex < 0)
                {
                    noteIndex += 12;
                }

                note = (InternalNote)(noteIndex % 12);

                if (direction > 0 && note == InternalNote.C)
                {
                    octave++;
                }
                else if (direction < 0 && note == InternalNote.B)
                {
                    octave--;
                }
            }

            return(new FullNote(NoteUtils.ToNote(note, style), octave));
        }
Пример #5
0
        public static async Task <ScaleFinderResultSet> FindScalesAsync(IScaleFinderOptions scaleFinderOptions, CancellationToken cancelToken)
        {
            if (null == scaleFinderOptions)
            {
                throw new ArgumentNullException("scaleFinderOptions");
            }

            InternalNote root  = NoteUtils.ToInternalNote(scaleFinderOptions.RootNote);
            IScale       scale = scaleFinderOptions.Scale;

            InternalNote[] notesInScale = NamedInterval.GetNotes(root, scale.Intervals);

            ScaleFinderResultSet results = new ScaleFinderResultSet(scaleFinderOptions);

            if (cancelToken.IsCancellationRequested)
            {
                return(results);
            }

            foreach (NoteNode startingNode in FindNodes(notesInScale[0], scaleFinderOptions))
            {
                await FindAllScalesAsync(results, startingNode, notesInScale, 1, startingNode.String, scaleFinderOptions, cancelToken);
            }

            return(results);
        }
Пример #6
0
 public NoteViewModel()
 {
     Note = new InternalNote()
     {
         PostDate = DateTime.Now
     };
 }
Пример #7
0
        public int AddInternalNote(InternalNote oData)
        {
            methodName = "AddInternalNote";
            traceID    = 1;

            using (var uow = new UnitOfWork(AppConfig.Current.ContextName))
            {
                using (var trans = uow.BeginTransaction())
                {
                    try
                    {
                        traceID = 2;
                        InternalNote oNewInternalNote = new InternalNote();
                        oNewInternalNote.MapFrom(oData);
                        oNewInternalNote = uow.InternalNote.Add(oNewInternalNote);
                        uow.Save();

                        traceID  = 3;
                        oData.Id = oNewInternalNote.Id;
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw new AppException(500, methodName, traceID, ex);
                    }
                }
            }

            return(oData.Id);
        }
Пример #8
0
        private InternalNote GetData()
        {
            InternalNote oData = new InternalNote();

            if (this.Selectkontak != null)
            {
                oData.IdKontak   = this.Selectkontak.Id;
                oData.NamaKontak = this.Selectkontak.NamaA;
            }
            if (this.selecttype != null)
            {
                oData.IdNoteType = this.selecttype.Id;
                oData.NoteType   = this.selecttype.Type;
            }
            if (this.Selectdepartment != null)
            {
                oData.IdDepartemen = this.Selectdepartment.Id;
            }
            else if (this.Selectproyek != null)
            {
                oData.IdProyek = this.Selectproyek.Id;
            }
            if (this.internalnoteform.internalnoteSelected != null)
            {
                oData.Id = this.internalnoteform.internalnoteSelected.Id;
            }

            return(oData);
        }
Пример #9
0
        public static InternalNote Shift(InternalNote root, int steps)
        {
            int newNote = ((int)root + steps);

            while (newNote < 0)
            {
                newNote += 12;
            }

            return((InternalNote)(newNote % 12));
        }
Пример #10
0
        public static int GetShift(InternalNote root, InternalNote targetNote)
        {
            int shift = (int)targetNote - (int)root;

            while (shift < 0)
            {
                shift += 12;
            }

            return(shift);
        }
Пример #11
0
        public InternalNote[] GetNotes(InternalNote root)
        {
            InternalNote[] notes = new InternalNote[Intervals.Length];

            for (int i = 0; i < notes.Length; i++)
            {
                notes[i] = NoteUtils.Shift(root, Intervals[i]);
            }

            return(notes);
        }
Пример #12
0
        private static async Task FindAllScalesAsync(ScaleFinderResultSet results, NoteNode noteNode, InternalNote[] targetNotes, int nextNote, int str, IScaleFinderOptions scaleFinderOptions, CancellationToken cancelToken)
        {
            if (cancelToken.IsCancellationRequested)
            {
                return;
            }

            IInstrument instrument = scaleFinderOptions.Instrument;

            if (nextNote == targetNotes.Length) // Build a scale result
            {
                List <MarkPosition> marks = new List <MarkPosition>();

                NoteNode nn = noteNode;

                // Walk back up the tree to set the marks on the result and flag each target note
                while (null != nn)
                {
                    if (nn.Fret >= 0)
                    {
                        marks.Add(new MarkPosition(nn.String + 1, nn.Fret));
                    }

                    nn = nn.Parent;
                }

                results.AddResult(marks);
            }
            else if (str < instrument.NumStrings) // Keep building the tree
            {
                // Look at all the notes on the string
                int startingFret = scaleFinderOptions.AllowOpenStrings ? 0 : 1;

                if (null != noteNode && noteNode.String == str)
                {
                    startingFret = noteNode.Fret + 1;
                }

                for (int fret = startingFret; fret <= scaleFinderOptions.MaxFret; fret++)
                {
                    InternalNote note = NoteUtils.Shift(scaleFinderOptions.Tuning.RootNotes[str].InternalNote, fret);

                    // See if the note is the next target note
                    if (note == targetNotes[nextNote])
                    {
                        NoteNode child = new NoteNode(str, fret, note, noteNode);                                                  // Add found note
                        await FindAllScalesAsync(results, child, targetNotes, nextNote + 1, str, scaleFinderOptions, cancelToken); // Look for the next note on the same string
                    }
                }

                await FindAllScalesAsync(results, noteNode, targetNotes, nextNote, str + 1, scaleFinderOptions, cancelToken); // Look for the next note on the next string
            }
        }
Пример #13
0
        private static IEnumerable <NoteNode> FindNodes(InternalNote targetNote, IScaleFinderOptions scaleFinderOptions)
        {
            for (int str = 0; str < scaleFinderOptions.Instrument.NumStrings; str++)
            {
                InternalNote rootNote = scaleFinderOptions.Tuning.RootNotes[str].InternalNote;

                int fret = NoteUtils.GetShift(rootNote, targetNote);

                while (fret <= scaleFinderOptions.MaxFret)
                {
                    yield return(new NoteNode(str, fret, targetNote, null));

                    fret += 12;
                }
            }
        }
Пример #14
0
        public static InternalNote[] GetNotes(InternalNote root, int[] intervals)
        {
            if (null == intervals || intervals.Length == 0)
            {
                throw new ArgumentNullException(nameof(intervals));
            }

            InternalNote[] notes = new InternalNote[intervals.Length];

            for (int i = 0; i < notes.Length; i++)
            {
                notes[i] = NoteUtils.Shift(root, intervals[i]);
            }

            return(notes);
        }
Пример #15
0
        public int CompareTo(object obj)
        {
            if (null == obj)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            FullNote fullNote = obj as FullNote;

            if (null == fullNote)
            {
                throw new ArgumentException();
            }

            if (Octave == fullNote.Octave)
            {
                return(InternalNote.CompareTo(fullNote.InternalNote));
            }

            return(Octave.CompareTo(fullNote.Octave));
        }
Пример #16
0
        public IHttpActionResult AddInternalNote(Guid TicketId, InternalNote Note, Guid StaffId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var ticket = _context.Tickets.SingleOrDefault(t => t.Id == TicketId);

            if (ticket == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Note.TicketId = TicketId;
            Note.Id       = Guid.NewGuid();
            Note.AuthorId = StaffId;
            _context.InternalNotes.Add(Note);

            return(Created(new Uri(Request.RequestUri + "/" + Note.Id), Note));
        }
Пример #17
0
        public static async Task <ChordFinderResultSet> FindChordsAsync(IChordFinderOptions chordFinderOptions, CancellationToken cancelToken)
        {
            if (null == chordFinderOptions)
            {
                throw new ArgumentNullException("chordFinderOptions");
            }

            InternalNote  root         = NoteUtils.ToInternalNote(chordFinderOptions.RootNote);
            IChordQuality chordQuality = chordFinderOptions.ChordQuality;

            InternalNote[] notesInChord = NamedInterval.GetNotes(root, chordQuality.Intervals);

            ChordFinderResultSet results = new ChordFinderResultSet(chordFinderOptions);

            if (cancelToken.IsCancellationRequested)
            {
                return(results);
            }

            await FindAllChordsAsync(results, null, notesInChord, 0, chordFinderOptions, cancelToken);

            return(results);
        }
Пример #18
0
        public Diagram ToDiagram(ChordFinderStyle chordFinderStyle)
        {
            int[] marks = MarkUtils.AbsoluteToRelativeMarks(Marks, out int baseLine, Parent.ChordFinderOptions.NumFrets);

            InternalNote?[] notes    = MarkUtils.GetInternalNotes(Marks, Parent.ChordFinderOptions.Tuning);
            InternalNote    rootNote = NoteUtils.ToInternalNote(Parent.ChordFinderOptions.RootNote);

            if (chordFinderStyle.MirrorResults)
            {
                Array.Reverse(marks);
                Array.Reverse(notes);
            }

            int numStrings = marks.Length;

            int numFrets = Parent.ChordFinderOptions.NumFrets;

            Diagram d = new Diagram(chordFinderStyle.Style, numStrings, numFrets);

            if (chordFinderStyle.AddTitle)
            {
                d.Title = NoteUtils.ToString(Parent.ChordFinderOptions.RootNote) + Parent.ChordFinderOptions.ChordQuality.Abbreviation;
                d.Style.TitleLabelStyle = DiagramLabelStyle.ChordName;
            }

            // Add marks
            for (int i = 0; i < marks.Length; i++)
            {
                int @string = i + 1;

                int          fret = Math.Max(marks[i], 0);
                MarkPosition mp   = new MarkPosition(@string, fret);

                DiagramMark dm = d.NewMark(mp);

                // Set mark type
                if (marks[i] == -1) // Muted string
                {
                    dm.Type = DiagramMarkType.Muted;
                }
                else if (marks[i] == 0) // Open string
                {
                    dm.Type = DiagramMarkType.Open;
                }

                // Change to root if necessary
                if (chordFinderStyle.AddRootNotes && notes[i].HasValue && notes[i].Value == rootNote)
                {
                    dm.Type = (dm.Type == DiagramMarkType.Open) ? DiagramMarkType.OpenRoot : DiagramMarkType.Root;
                }

                // Add text
                if (chordFinderStyle.MarkTextOption != MarkTextOption.None)
                {
                    dm.Text = GetText(notes, i, chordFinderStyle.MarkTextOption);
                }

                // Add bottom marks
                if (chordFinderStyle.AddBottomMarks)
                {
                    MarkPosition bottomPosition = new MarkPosition(@string, numFrets + 1);
                    DiagramMark  bottomMark     = d.NewMark(bottomPosition);
                    bottomMark.Type = DiagramMarkType.Bottom;
                    bottomMark.Text = GetText(notes, i, chordFinderStyle.BottomMarkTextOption);
                }
            }

            // Add nut or fret label
            if (baseLine == 0)
            {
                d.Style.GridNutVisible = true;
            }
            else
            {
                d.Style.GridNutVisible = false;
                FretLabelPosition flp = new FretLabelPosition(chordFinderStyle.FretLabelSide, 1);
                d.NewFretLabel(flp, baseLine.ToString());
            }

            // Add barre
            BarrePosition bp = MarkUtils.AutoBarrePosition(marks, chordFinderStyle.BarreTypeOption, chordFinderStyle.MirrorResults);

            if (null != bp)
            {
                d.NewBarre(bp);
            }

            return(d);
        }
Пример #19
0
 public InternalNote[] GetNotes(InternalNote root)
 {
     return(NamedInterval.GetNotes(root, Intervals));
 }
Пример #20
0
        private void FindAllChords(ChordResultSet results, NoteNode noteNode, InternalNote[] targetNotes, int str, ChordFinderOptions chordFinderOptions)
        {
            if (str == Instrument.NumStrings) // Build a chord result
            {
                int[] marks = new int[Instrument.NumStrings];

                NoteNode nn = noteNode;
                str--;

                bool[] hasNotes = new bool[targetNotes.Length];

                // Walk back up the tree to set the marks on the result and flag each target note
                while (nn != null)
                {
                    marks[str] = nn.Fret;

                    for (int i = 0; i < targetNotes.Length; i++)
                    {
                        if (nn.Note == targetNotes[i])
                        {
                            hasNotes[i] = true;
                            break;
                        }
                    }

                    nn = nn.Parent;
                    str--;
                }

                // The first target note is always the root, so ignore if we want
                // to allow rootless chords
                int firstTargetNote = chordFinderOptions.AllowRootlessChords ? 1 : 0;

                // Add result if it had all the target notes
                bool valid = true;
                for (int i = firstTargetNote; i < hasNotes.Length; i++)
                {
                    valid = valid && hasNotes[i];
                }

                if (valid)
                {
                    results.AddResult(marks);
                }
            }
            else // Keep building the tree
            {
                // Look at the muted string
                if (chordFinderOptions.AllowMutedStrings)
                {
                    NoteNode muted = new NoteNode();
                    muted.Parent = noteNode;
                    FindAllChords(results, muted, targetNotes, str + 1, chordFinderOptions);
                }

                // Look at all the notes on the string
                int startingFret = chordFinderOptions.AllowOpenStrings ? 0 : 1;
                for (int fret = startingFret; fret <= chordFinderOptions.MaxFret; fret++)
                {
                    InternalNote note = Tuning.NoteAt(str, fret);

                    // See if the note is a target note
                    for (int i = 0; i < targetNotes.Length; i++)
                    {
                        // If it's a target note add it and search on the next string
                        if (note == targetNotes[i])
                        {
                            NoteNode child = new NoteNode(fret, note, noteNode);
                            FindAllChords(results, child, targetNotes, str + 1, chordFinderOptions);
                            break;
                        }
                    }
                }
            }
        }
Пример #21
0
        public static Note ToNote(InternalNote note, InternalNoteStringStyle style)
        {
            switch (note)
            {
            case InternalNote.C:
                return(Note.C);

            case InternalNote.Cs_Db:
                if (style == InternalNoteStringStyle.PreferSharp)
                {
                    return(Note.Cs);
                }
                else if (style == InternalNoteStringStyle.PreferFlat)
                {
                    return(Note.Db);
                }
                break;

            case InternalNote.D:
                return(Note.D);

            case InternalNote.Ds_Eb:
                if (style == InternalNoteStringStyle.PreferSharp)
                {
                    return(Note.Ds);
                }
                else if (style == InternalNoteStringStyle.PreferFlat)
                {
                    return(Note.Eb);
                }
                break;

            case InternalNote.E:
                return(Note.E);

            case InternalNote.F:
                return(Note.F);

            case InternalNote.Fs_Gb:
                if (style == InternalNoteStringStyle.PreferSharp)
                {
                    return(Note.Fs);
                }
                else if (style == InternalNoteStringStyle.PreferFlat)
                {
                    return(Note.Gb);
                }
                break;

            case InternalNote.G:
                return(Note.G);

            case InternalNote.Gs_Ab:
                if (style == InternalNoteStringStyle.PreferSharp)
                {
                    return(Note.Gs);
                }
                else if (style == InternalNoteStringStyle.PreferFlat)
                {
                    return(Note.Ab);
                }
                break;

            case InternalNote.A:
                return(Note.A);

            case InternalNote.As_Bb:
                if (style == InternalNoteStringStyle.PreferSharp)
                {
                    return(Note.As);
                }
                else if (style == InternalNoteStringStyle.PreferFlat)
                {
                    return(Note.Bb);
                }
                break;

            case InternalNote.B:
                return(Note.B);
            }

            throw new ArgumentException();
        }
Пример #22
0
        private static async Task FindAllChordsAsync(ChordFinderResultSet results, NoteNode noteNode, InternalNote[] targetNotes, int str, IChordFinderOptions chordFinderOptions, CancellationToken cancelToken)
        {
            if (cancelToken.IsCancellationRequested)
            {
                return;
            }

            IInstrument instrument = chordFinderOptions.Instrument;

            if (str == instrument.NumStrings) // Build a chord result
            {
                int[] marks = new int[instrument.NumStrings];

                NoteNode nn = noteNode;
                str--;

                bool[] hasNotes = new bool[targetNotes.Length];

                // Walk back up the tree to set the marks on the result and flag each target note
                while (null != nn)
                {
                    marks[str] = nn.Fret;

                    for (int i = 0; i < targetNotes.Length; i++)
                    {
                        if (nn.Note == targetNotes[i])
                        {
                            hasNotes[i] = true;
                        }
                    }

                    nn = nn.Parent;
                    str--;
                }

                InternalNote rootNote = NoteUtils.ToInternalNote(chordFinderOptions.RootNote);

                // Add result if it had all the target notes
                bool valid = true;
                for (int i = 0; i < hasNotes.Length; i++)
                {
                    // Validate:
                    // 1. All notes when !AllowRootlessChords
                    // 2. Non-root notes only when AllowRootlessChords
                    if (!chordFinderOptions.AllowRootlessChords ||
                        (chordFinderOptions.AllowRootlessChords && targetNotes[i] != rootNote))
                    {
                        valid = valid && hasNotes[i];
                    }
                }

                if (valid)
                {
                    results.AddResult(marks);
                }
            }
            else // Keep building the tree
            {
                // Look at the muted string
                if (chordFinderOptions.AllowMutedStrings)
                {
                    NoteNode muted = new NoteNode();
                    muted.Parent = noteNode;
                    await FindAllChordsAsync(results, muted, targetNotes, str + 1, chordFinderOptions, cancelToken);
                }

                // Look at all the notes on the string
                int startingFret = chordFinderOptions.AllowOpenStrings ? 0 : 1;
                for (int fret = startingFret; fret <= chordFinderOptions.MaxFret; fret++)
                {
                    InternalNote note = NoteUtils.Shift(chordFinderOptions.Tuning.RootNotes[str].InternalNote, fret);

                    // See if the note is a target note
                    for (int i = 0; i < targetNotes.Length; i++)
                    {
                        // If it's a target note add it and search on the next string
                        if (note == targetNotes[i])
                        {
                            NoteNode child = new NoteNode(fret, note, noteNode);
                            await FindAllChordsAsync(results, child, targetNotes, str + 1, chordFinderOptions, cancelToken);

                            break;
                        }
                    }
                }
            }
        }
Пример #23
0
 public static bool IsNatural(InternalNote note)
 {
     return(Array.IndexOf <InternalNote>(NaturalInternalNotes, note) >= 0);
 }