예제 #1
0
        /// <summary>
        /// Saves measures to db.
        /// </summary>
        /// <param name="measure">
        /// The measure.
        /// </param>
        /// <returns>
        /// The <see cref="long"/>.
        /// </returns>
        public long CreateMeasure(Measure measure)
        {
            var measureChain = new BaseChain(measure.NoteList.Cast <IBaseObject>().ToList());

            long[] notes = new ElementRepository(db).GetOrCreateNotesInDb(measureChain.Alphabet);

            string localMeasureHash = measure.GetHashCode().ToString();
            var    dbMeasures       = db.Measure.Where(m => m.Value == localMeasureHash).ToList();

            if (dbMeasures.Count > 0)
            {
                foreach (var dbMeasure in dbMeasures)
                {
                    long[] dbAlphabet = db.GetMeasureAlphabet(dbMeasure.Id);
                    if (notes.SequenceEqual(dbAlphabet))
                    {
                        int[] dbBuilding = db.GetMeasureBuilding(dbMeasure.Id);
                        if (measureChain.Building.SequenceEqual(dbBuilding))
                        {
                            if (measure.Attributes.Key.Fifths != dbMeasure.Fifths ||
                                measure.Attributes.Size.BeatBase != dbMeasure.Beatbase ||
                                measure.Attributes.Size.Beats != dbMeasure.Beats)
                            {
                                throw new Exception("Found in db measure is not equal to local measure.");
                            }

                            return(dbMeasure.Id);
                        }
                    }
                }
            }

            return(Create(measure, notes, measureChain.Building));
        }
예제 #2
0
        /// <summary>
        /// Saves Fmotifs to db.
        /// </summary>
        /// <param name="fmotif">
        /// The Fmotif.
        /// </param>
        /// <returns>
        /// The <see cref="long"/>.
        /// </returns>
        public long CreateFmotif(Fmotif fmotif)
        {
            var fmotifChain = new BaseChain(fmotif.NoteList.Cast <IBaseObject>().ToList());

            long[] notes = new ElementRepository(db).GetOrCreateNotesInDb(fmotifChain.Alphabet);

            var localFmotifHash = fmotif.GetHashCode().ToString();
            var dbFmotifs       = db.Fmotif.Where(f => f.Value == localFmotifHash).ToList();

            if (dbFmotifs.Count > 0)
            {
                foreach (var dbFmotif in dbFmotifs)
                {
                    long[] dbAlphabet = db.GetFmotifAlphabet(dbFmotif.Id);
                    if (notes.SequenceEqual(dbAlphabet))
                    {
                        int[] dbBuilding = db.GetFmotifBuilding(dbFmotif.Id);
                        if (fmotifChain.Building.SequenceEqual(dbBuilding))
                        {
                            if (fmotif.Type != dbFmotif.FmotifType)
                            {
                                throw new Exception("Found in db fmotif is not equal to local fmotif.");
                            }

                            return(dbFmotif.Id);
                        }
                    }
                }
            }

            return(Create(fmotif, notes, fmotifChain.Building));
        }