Esempio n. 1
0
        private bool TryAddObjectToNewNoteBag(ITimedObject timedObject, ObjectsBuildingSettings settings)
        {
            var bag = new NotesBag();

            if (!bag.TryAddObject(timedObject, null, settings))
            {
                return(false);
            }

            var newNoteTime    = bag.Time;
            var newNoteChannel = bag.NoteId.Channel;

            if (_chordStart < 0)
            {
                _notesBags.Add(bag);
                _chordStart   = newNoteTime;
                _chordChannel = newNoteChannel;
                return(true);
            }
            else
            {
                if (newNoteTime - _chordStart > settings.ChordBuilderSettings.NotesTolerance || newNoteChannel != _chordChannel)
                {
                    _canObjectsBeAdded = !IsCompleted;
                    return(false);
                }

                _notesBags.Add(bag);
                return(true);
            }
        }
        private static IEnumerable <ITimedObject> AddObjectsByPostBuilders(
            IEnumerable <ITimedObject> inputTimedObjects,
            IEnumerable <ITimedObject> resultTimedObjects,
            ObjectsBuildingSettings settings)
        {
            var builders = new IOverlayBuilder[]
            {
                settings.BuildRests ? new RestsBuilder() : null
            }
            .Where(b => b != null)
            .ToArray();

            if (builders.Any())
            {
                var resultList = resultTimedObjects.ToList();

                foreach (var builder in builders)
                {
                    resultList.AddRange(builder.BuildObjects(inputTimedObjects, resultTimedObjects, settings));
                }

                resultTimedObjects = resultList.OrderBy(o => o.Time);
            }

            return(resultTimedObjects);
        }
Esempio n. 3
0
        public SequentialObjectsBuilder(List <ObjectsBag> objectsBags, ObjectsBuildingSettings settings)
        {
            _objectsBags = objectsBags;
            _settings    = settings;

            _context = new TContext();
        }
Esempio n. 4
0
        private bool TryAddNote(Note note, ObjectsBuildingSettings settings)
        {
            if (note == null)
            {
                return(false);
            }

            return(TryAddObjectToNewNoteBag(note, settings));
        }
        public static IEnumerable <ITimedObject> BuildObjects(
            this IEnumerable <ITimedObject> timedObjects,
            ObjectsBuildingSettings settings)
        {
            ThrowIfArgument.IsNull(nameof(timedObjects), timedObjects);
            ThrowIfArgument.IsNull(nameof(settings), settings);

            timedObjects = timedObjects.OrderBy(o => o.Time);

            var result = BuildObjects(timedObjects, settings, 0);

            result = AddObjectsByPostBuilders(timedObjects, result, settings);

            return(result);
        }
Esempio n. 6
0
        private bool TryAddTimedEvent(TimedEvent timedEvent, ObjectsBuildingSettings settings)
        {
            if (timedEvent == null)
            {
                return(false);
            }

            var handlingBag = _notesBags.FirstOrDefault(b => b.TryAddObject(timedEvent, null, settings));

            if (handlingBag != null)
            {
                return(true);
            }

            return(TryAddObjectToNewNoteBag(timedEvent, settings));
        }
Esempio n. 7
0
        public IEnumerable <ITimedObject> BuildObjects(
            IEnumerable <ITimedObject> inputTimedObjects,
            IEnumerable <ITimedObject> resultTimedObjects,
            ObjectsBuildingSettings settings)
        {
            var notes = settings.BuildNotes
                ? resultTimedObjects.OfType <Note>()
                : inputTimedObjects.BuildObjects(new ObjectsBuildingSettings {
                BuildNotes = true
            }).OfType <Note>();

            var restBuildingSettings = settings.RestBuilderSettings ?? new RestBuilderSettings();

            switch (restBuildingSettings.RestSeparationPolicy)
            {
            case RestSeparationPolicy.NoSeparation:
                return(GetRests(
                           notes,
                           n => NoSeparationNoteDescriptor,
                           setRestChannel: false,
                           setRestNoteNumber: false));

            case RestSeparationPolicy.SeparateByChannel:
                return(GetRests(
                           notes,
                           n => n.Channel,
                           setRestChannel: true,
                           setRestNoteNumber: false));

            case RestSeparationPolicy.SeparateByNoteNumber:
                return(GetRests(
                           notes,
                           n => n.NoteNumber,
                           setRestChannel: false,
                           setRestNoteNumber: true));

            case RestSeparationPolicy.SeparateByChannelAndNoteNumber:
                return(GetRests(
                           notes,
                           n => n.GetNoteId(),
                           setRestChannel: true,
                           setRestNoteNumber: true));
            }

            throw new NotSupportedException($"Rest separation policy {restBuildingSettings.RestSeparationPolicy} is not supported.");
        }
        private static IEnumerable <ITimedObject> BuildObjects(
            this IEnumerable <ITimedObject> timedObjects,
            ObjectsBuildingSettings settings,
            int buildersStartIndex)
        {
            var objectsBags = new List <ObjectsBag>();

            var builders = new ISequentialObjectsBuilder[]
            {
                settings.BuildChords ? new ChordsBuilder(objectsBags, settings) : null,
                settings.BuildNotes ? new NotesBuilder(objectsBags, settings) : null,
                settings.BuildRegisteredParameters ? new RegisteredParametersBuilder(objectsBags, settings) : null,
                settings.BuildTimedEvents ? new TimedEventsBuilder(objectsBags, settings) : null,
            }
            .Where(b => b != null)
            .Skip(buildersStartIndex)
            .ToArray();

            //

            foreach (var timedObject in timedObjects)
            {
                if (timedObject == null)
                {
                    // TODO: policy
                    continue;
                }

                var handlingBuilder = builders.FirstOrDefault(m => m.TryAddObject(timedObject));
                if (handlingBuilder == null)
                {
                    // TODO: policy
                    continue;
                }
            }

            //

            return(objectsBags
                   .SelectMany(b => b.IsCompleted
                    ? b.GetObjects()
                    : BuildObjects(b.GetRawObjects(), settings, buildersStartIndex + 1))
                   .OrderBy(o => o.Time));
        }
Esempio n. 9
0
 public NotesBuilder(List <ObjectsBag> objectsBags, ObjectsBuildingSettings settings)
     : base(objectsBags, settings)
 {
 }
Esempio n. 10
0
        public override bool TryAddObject(ITimedObject timedObject, IBuildingContext context, ObjectsBuildingSettings settings)
        {
            if (IsCompleted)
            {
                return(false);
            }

            return(TryAddTimedEvent(timedObject as TimedEvent) ||
                   TryAddNote(timedObject as Note) ||
                   TryAddChord(timedObject as Chord) ||
                   TryAddRegisteredParameter(timedObject as RegisteredParameter));
        }
Esempio n. 11
0
        public override bool TryAddObject(ITimedObject timedObject, IBuildingContext context, ObjectsBuildingSettings settings)
        {
            if (!CanObjectsBeAdded)
            {
                return(false);
            }

            return(TryAddTimedEvent(timedObject as TimedEvent, settings) ||
                   TryAddNote(timedObject as Note, settings) ||
                   TryAddChord(timedObject as Chord));
        }
Esempio n. 12
0
 public RegisteredParametersBuilder(List <ObjectsBag> objectsBags, ObjectsBuildingSettings settings)
     : base(objectsBags, settings)
 {
 }
Esempio n. 13
0
 public abstract bool TryAddObject(ITimedObject timedObject, IBuildingContext context, ObjectsBuildingSettings settings);
        public override bool TryAddObject(ITimedObject timedObject, IBuildingContext context, ObjectsBuildingSettings settings)
        {
            if (!CanObjectsBeAdded)
            {
                return(false);
            }

            var buildingContext = (RegisteredParametersContext)context;

            return(TryAddTimedEvent(timedObject as TimedEvent, buildingContext));
        }
Esempio n. 15
0
 public TimedEventsBuilder(List <ObjectsBag> objectsBags, ObjectsBuildingSettings settings)
     : base(objectsBags, settings)
 {
 }