Esempio n. 1
0
        public MusicTrack(
            EditorFile file,
            IStorageObject storage,
            TrackControllerSettings settings
            ) : base(
                storage.ID,
                file
                )
        {
            melody           = new MelodyTrack(storage.GetOrMake("melody").ID, file);
            rhythm           = new RhythmTrack(storage.GetOrMake("rhythm").ID, file);
            adornment        = new AdornmentTrack(storage.GetOrMake("adornment").ID, file);
            tempo            = new TempoTrack(storage.GetOrMake("tempo").ID, file);
            memory           = new PerceptualMemory();
            propertygraphlet = new StoragePropertyGraphlet <NoteID>(storage, propertymanager);
            propertymanager  = settings.PropertyManager;

            this.settings = settings;

            melody.FieldChanged += Melody_FieldChanged;
            rhythm.MeterSignatures.FieldChanged  += MeterSignatures_FieldChanged;
            rhythm.TimeSignatures.FieldChanged   += TimeSignatures_FieldChanged;
            adornment.KeySignatures.FieldChanged += KeySignatures_FieldChanged;
            adornment.Staffs.FieldChanged        += Staffs_FieldChanged;

            if (!storage.HasChild("state") || storage.Get("state").ReadAllString() != "inited")
            {
                Init();
                storage.GetOrMake("state").WriteAllString("inited");
            }

            Init_memory();
        }
        public bool Analyze(
            Duration delta,
            MusicBrain brain,
            PerceptualMemory memory
            )
        {
            bool flag = false;

            var memorymodule =
                (EditableMemoryModule <MeasureLayout>)
                memory.MemoryModule <MeasureLayout>();

            var measures =
                memory.Analyses <Measure>(delta);

            foreach (var measure in measures)
            {
                var duration =
                    measure.Duration;

                if (memorymodule.Knowledge.AnyItemIn(duration))
                {
                    continue;
                }

                var measure_notes =
                    memory
                    .Analyses <PerceptualNote>(duration)
                    .Select(note => note.Value)
                    .ToArray();

                var keysignature =
                    memory
                    .Analyses <KeySignature>(duration)
                    .First()
                    .Value;

                var staff =
                    memory
                    .Analyses <Staff>(duration)
                    .First()
                    .Value;

                var measurelayout =
                    new MeasureLayout(
                        duration,
                        measure_notes,
                        staff,
                        keysignature
                        );

                memorymodule.Editable.Add(measurelayout, duration);

                flag = true;
            }

            return(flag);
        }
Esempio n. 3
0
        public void Invalidate(
            PerceptualMemory memory,
            Duration duration
            )
        {
            memory.Forget(duration);

            bool flag;

            do
            {
                flag = false;

                foreach (var cog in cogs.Values)
                {
                    flag |= cog.Analyze(duration, this, memory);
                }
            }while (flag);
        }
        public bool Analyze(
            Duration delta,
            MusicBrain brain,
            PerceptualMemory memory
            )
        {
            bool flag = false;

            var memorymodule =
                (EditableMemoryModule <ChordLayout>)
                memory.MemoryModule <ChordLayout>();

            var builder =
                new Dictionary <Duration, List <NoteLayout> >();

            foreach (var notelayout in memory.Analyses <NoteLayout>(delta))
            {
                List <NoteLayout> list;

                if (!builder.TryGetValue(notelayout.Duration, out list))
                {
                    builder.Add(notelayout.Duration, list = new List <NoteLayout>());
                }

                list.Add(notelayout.Value);
            }

            foreach (var noteset in builder)
            {
                var chordlayout =
                    new ChordLayout(noteset.Value.ToArray());

                memorymodule.Editable.Add(chordlayout, noteset.Key);

                flag = true;
            }

            return(flag);
        }
        public bool Analyze(
            Duration duration,
            MusicBrain brain,
            PerceptualMemory memory
            )
        {
            bool flag = false;

            var memorymodule =
                (MemoryModule)
                memory.MemoryModule <PerceptualNote>();

            var measures =
                memory.MemoryModule <Measure>();

            var notes =
                memory.Analyses <Note>(duration);

            foreach (Note note in notes)
            {
                if (memorymodule.perceptualnotes_map.ContainsKey(note.ID))
                {
                    continue;
                }

                var perceptualnotes =
                    new List <PerceptualNote>();

                var singlelength =
                    PerceptualTime.Decompose(note.Duration.Length).OneOrNothing();

                var cells =
                    memory.Analyses <Cell>(note.Duration);

                var measures_intersecting =
                    measures
                    .Knowledge
                    .Intersecting(note.Duration);

                if (singlelength.Key == default(PerceptualTime) || measures_intersecting.Count() > 1)
                {
                    var i = 0;

                    foreach (var cell_durateditem in cells)
                    {
                        var cell         = cell_durateditem.Value;
                        var cellduration = cell_durateditem.Duration;

                        var cellcutduration = cellduration.Intersection(note.Duration);

                        var lengths =
                            PerceptualTime.Decompose(cellcutduration.Length);

                        foreach (var length in lengths)
                        {
                            var cutduration =
                                new Duration {
                                Start  = length.Value + cellduration.Start,
                                Length = length.Key.TimeLength()
                            };

                            var perceptualnote =
                                new PerceptualNote(
                                    new PerceptualNoteID(note.ID, i++),
                                    cutduration,
                                    length.Key,
                                    cell_durateditem,
                                    note
                                    );

                            memorymodule.Editable.Add(perceptualnote, cutduration);

                            perceptualnotes.Add(perceptualnote);
                        }
                    }

                    if (perceptualnotes.Count > 0)
                    {
                        memorymodule.perceptualnotes_map.Add(note.ID, perceptualnotes.ToArray());
                        flag = true;
                    }
                }
                else
                {
                    var perceptualnote =
                        new PerceptualNote(
                            new PerceptualNoteID(
                                note.ID,
                                0
                                ),
                            note.Duration,
                            singlelength.Key,
                            cells.First(),
                            note
                            );

                    memorymodule.Editable.Add(perceptualnote, note.Duration);

                    memorymodule.perceptualnotes_map.Add(note.ID, new[] { perceptualnote });
                    flag = true;
                }
            }

            return(flag);
        }
        public bool Analyze(
            Duration delta,
            MusicBrain brain,
            PerceptualMemory memory
            )
        {
            bool flag = false;

            var memorymodule =
                (MemoryModule)
                memory.MemoryModule <NoteLayout>();

            var perceptualnotes_items =
                memory.Analyses <PerceptualNote>(delta);

            foreach (var perceptualnote_item in perceptualnotes_items)
            {
                if (memorymodule.known_notes.Contains(perceptualnote_item.Value.ID))
                {
                    continue;
                }

                memorymodule.known_notes.Add(perceptualnote_item.Value.ID);

                var staff =
                    memory
                    .Analyses <Staff>(perceptualnote_item.Duration)
                    .Single()
                    .Value;

                var keysignature =
                    memory
                    .Analyses <KeySignature>(perceptualnote_item.Duration)
                    .Single()
                    .Value;

                PitchTransform transform;

                var key =
                    keysignature.Key(
                        perceptualnote_item.Value.Note.Tone,
                        out transform
                        );

                var halfline =
                    staff.GetHalfLine(key);

                var x =
                    0.01F *
                    (perceptualnote_item.Duration.Start / Time.Note_128th_3rd_5th_7th);

                var notelayout =
                    new NoteLayout(
                        perceptualnote_item.Value,
                        halfline,
                        x,
                        0,
                        key,
                        transform
                        );

                memorymodule.Editable.Add(notelayout, perceptualnote_item.Duration);

                flag = true;
            }

            return(flag);
        }