public static void OnSampleRequest(string id)
 {
     if (Lookup.ContainsKey(id) && Lookup[id].SampleRequest != null)
     {
         Lookup[id].SampleRequest();
     }
 }
Ejemplo n.º 2
0
 public static void OnReady(string id)
 {
     if (Lookup.ContainsKey(id))
     {
         Lookup[id].Ready();
     }
 }
Ejemplo n.º 3
0
 public void RegisterBarRenderer(string key, BarRendererBase renderer)
 {
     if (!_barRendererLookup.ContainsKey(key))
     {
         _barRendererLookup[key] = new FastDictionary <string, BarRendererBase>();
     }
     _barRendererLookup[key][GetBarRendererId(renderer.Bar.Staff.Track.Index, renderer.Bar.Index)] = renderer;
 }
Ejemplo n.º 4
0
 public MasterBarBounds FindMasterBarByIndex(int index)
 {
     if (_masterBarLookup.ContainsKey(index))
     {
         return(_masterBarLookup[index]);
     }
     return(null);
 }
 public void RegisterBarRenderer(string key, int index, BarRendererBase renderer)
 {
     if (!_barRendererLookup.ContainsKey(key))
     {
         _barRendererLookup[key] = new FastDictionary <int, BarRendererBase>();
     }
     _barRendererLookup[key][index] = renderer;
 }
Ejemplo n.º 6
0
 public float GetNoteValueY(int noteValue, bool aboveNote = false)
 {
     if (_noteValueLookup.ContainsKey(noteValue))
     {
         return(Y + _noteValueLookup[noteValue].Y + (aboveNote ? -(NoteHeadGlyph.NoteHeadHeight * NoteHeadGlyph.GraceScale * Scale) / 2 : 0));
     }
     return(0);
 }
Ejemplo n.º 7
0
 public float GetNoteX(Note note, bool onEnd = true)
 {
     if (_noteLookup.ContainsKey(note.String))
     {
         var n   = _noteLookup[note.String];
         var pos = X + n.X;
         if (onEnd)
         {
             pos += n.Width;
         }
         return(pos);
     }
     return(0);
 }
Ejemplo n.º 8
0
        private int FindStringForValue(Track track, Beat beat, int value)
        {
            // find strings which are already taken
            var takenStrings = new FastDictionary<int, bool>();
            for (int i = 0; i < beat.Notes.Count; i++)
            {
                var note = beat.Notes[i];
                takenStrings[note.String] = true;
            }

            // find a string where the note matches into 0 to <upperbound>

            // first try to find a string from 0-14 (more handy to play)
            // then try from 0-20 (guitars with high frets)
            // then unlimited 
            int[] steps = { 14, 20, int.MaxValue };
            for (int i = 0; i < steps.Length; i++)
            {
                for (int j = 0; j < track.Tuning.Length; j++)
                {
                    if (!takenStrings.ContainsKey(j))
                    {
                        var min = track.Tuning[j];
                        var max = track.Tuning[j] + steps[i];

                        if (value >= min && value <= max)
                        {
                            return track.Tuning.Length - j;
                        }
                    }
                }
            }
            // will not happen
            return 1;
        }
Ejemplo n.º 9
0
        private void FillWorkingBuffer(bool silent)
        {
            /*Break the process loop into sections representing the smallest timeframe before the midi controls need to be updated
             * the bigger the timeframe the more efficent the process is, but playback quality will be reduced.*/
            var sampleIndex = 0;
            var anySolo     = _isAnySolo;

            for (int x = 0; x < MicroBufferCount; x++)
            {
                if (_midiEventQueue.Length > 0)
                {
                    for (int i = 0; i < _midiEventCounts[x]; i++)
                    {
                        var m = _midiEventQueue.RemoveLast();
                        if (m.IsMetronome)
                        {
                            NoteOff(_metronomeChannel, 37);
                            NoteOn(_metronomeChannel, 37, 95);
                        }
                        else
                        {
                            ProcessMidiMessage(m.Event);
                        }
                    }
                }
                //voice processing loop
                var node = _voiceManager.ActiveVoices.First; //node used to traverse the active voices
                while (node != null)
                {
                    var channel = node.Value.VoiceParams.Channel;
                    // channel is muted if it is either explicitley muted, or another channel is set to solo but not this one.
                    var isChannelMuted = _mutedChannels.ContainsKey(channel) ||
                                         (anySolo && !_soloChannels.ContainsKey(channel));

                    if (silent)
                    {
                        node.Value.ProcessSilent(sampleIndex, sampleIndex + MicroBufferSize * 2);
                    }
                    else
                    {
                        node.Value.Process(sampleIndex, sampleIndex + MicroBufferSize * 2, isChannelMuted);
                    }
                    //if an active voice has stopped remove it from the list
                    if (node.Value.VoiceParams.State == VoiceStateEnum.Stopped)
                    {
                        var delnode = node; //node used to remove inactive voices
                        node = node.Next;
                        _voiceManager.RemoveVoiceFromRegistry(delnode.Value);
                        _voiceManager.ActiveVoices.Remove(delnode);
                        _voiceManager.FreeVoices.AddFirst(delnode.Value);
                    }
                    else
                    {
                        node = node.Next;
                    }
                }
                sampleIndex += MicroBufferSize * SynthConstants.AudioChannels;
            }
            Platform.Platform.ClearIntArray(_midiEventCounts);
        }
Ejemplo n.º 10
0
        private void ParsePart(IXmlNode element)
        {
            var id = element.GetAttribute("id");

            if (!_trackById.ContainsKey(id))
            {
                return;
            }

            var track          = _trackById[id];
            var isFirstMeasure = true;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "measure":
                        if (ParseMeasure(c, track, isFirstMeasure))
                        {
                            isFirstMeasure = false;
                        }
                        break;
                    }
                }
            });
        }
Ejemplo n.º 11
0
        private int FindStringForValue(Track track, Beat beat, int value)
        {
            // find strings which are already taken
            var takenStrings = new FastDictionary<int, bool>();
            for (int i = 0; i < beat.Notes.Count; i++)
            {
                var note = beat.Notes[i];
                takenStrings[note.String] = true;
            }

            // find a string where the note matches into 0 to <upperbound>

            // first try to find a string from 0-14 (more handy to play)
            // then try from 0-20 (guitars with high frets)
            // then unlimited
            int[] steps = { 14, 20, int.MaxValue };
            for (int i = 0; i < steps.Length; i++)
            {
                for (int j = 0; j < track.Tuning.Length; j++)
                {
                    if (!takenStrings.ContainsKey(j))
                    {
                        var min = track.Tuning[j];
                        var max = track.Tuning[j] + steps[i];

                        if (value >= min && value <= max)
                        {
                            return track.Tuning.Length - j;
                        }
                    }
                }
            }
            // will not happen
            return 1;
        }
Ejemplo n.º 12
0
        public EffectBandSlot GetOrCreateSlot(EffectBand band)
        {
            // first check preferrable slot depending on type
            if (_effectSlot.ContainsKey(band.Info.EffectId))
            {
                var slot = _effectSlot[band.Info.EffectId];
                if (slot.CanBeUsed(band))
                {
                    return(slot);
                }
            }

            // find any slot that can be used
            foreach (var slot in Slots)
            {
                if (slot.CanBeUsed(band))
                {
                    return(slot);
                }
            }

            // create a new slot if required
            var newSlot = new EffectBandSlot();

            Slots.Add(newSlot);
            return(newSlot);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Gets the default tuning for the given string count.
 /// </summary>
 /// <param name="stringCount">The string count. </param>
 /// <returns>The tuning for the given string count or null if the string count is not defined. </returns>
 public static Tuning GetDefaultTuningFor(int stringCount)
 {
     if (_defaultTunings.ContainsKey(stringCount))
     {
         return(_defaultTunings[stringCount]);
     }
     return(null);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Registers for the specified event.
 /// </summary>
 /// <param name="events">The event to register for</param>
 /// <param name="action">The function to call on the event.</param>
 public void On(string events, Action action)
 {
     if (!_events.ContainsKey(events))
     {
         _events[events] = new FastList <JsFunction>();
     }
     _events[events].Add(action.As <JsFunction>());
 }
Ejemplo n.º 15
0
 public T GetSetting <T>(string key, T def)
 {
     if (_settings.ContainsKey(key))
     {
         return((T)(_settings[key]));
     }
     return(def);
 }
Ejemplo n.º 16
0
 internal T Get <T>(string key, T def)
 {
     if (AdditionalSettings.ContainsKey(key.ToLower()))
     {
         return((T)(AdditionalSettings[key.ToLower()]));
     }
     return(def);
 }
Ejemplo n.º 17
0
 public T Get <T>(string key, T def)
 {
     if (AdditionalSettings.ContainsKey(key))
     {
         return((T)(AdditionalSettings[key]));
     }
     return(def);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Registers for the specified event.
 /// </summary>
 /// <param name="events">The event to register for</param>
 /// <param name="action">The function to call on the event.</param>
 public void On(string events, Delegate action)
 {
     if (!_events.ContainsKey(events))
     {
         _events[events] = new FastList <Delegate>();
     }
     _events[events].Add(action.As <Delegate>());
 }
Ejemplo n.º 19
0
 public CollectionBuilder <T> Set(uint index, T val)
 {
     if (m_Dictionary.ContainsKey(index))
     {
         throw new InvalidOperationException($"Key '{index}' already exist!");
     }
     m_Dictionary[index] = val;
     return(this);
 }
Ejemplo n.º 20
0
        internal Beat GetBeatAtDisplayStart(int displayStart)
        {
            if (_beatLookup.ContainsKey(displayStart))
            {
                return(_beatLookup[displayStart]);
            }

            return(null);
        }
Ejemplo n.º 21
0
        public T GetSharedLayoutData <T>(string key, T def)
        {
            if (_sharedLayoutData.ContainsKey(key))
            {
                return((T)_sharedLayoutData[key]);
            }

            return(def);
        }
Ejemplo n.º 22
0
        private AccidentalType GetAccidental(int line, int noteValue, bool quarterBend)
        {
            var accidentalToSet = AccidentalType.None;

            if (_bar.Staff.StaffKind != StaffKind.Percussion)
            {
                var ks    = (int)_bar.MasterBar.KeySignature;
                var ksi   = (ks + 7);
                var index = (noteValue % 12);

                // the key signature symbol required according to
                var keySignatureAccidental = ksi < 7 ? AccidentalType.Flat : AccidentalType.Sharp;

                // determine whether the current note requires an accidental according to the key signature
                var hasNoteAccidentalForKeySignature = KeySignatureLookup[ksi][index];
                var isAccidentalNote = AccidentalNotes[index];

                if (quarterBend)
                {
                    accidentalToSet = isAccidentalNote ? keySignatureAccidental : AccidentalType.Natural;
                }
                else
                {
                    var isAccidentalRegistered = _registeredAccidentals.ContainsKey(line);
                    if (hasNoteAccidentalForKeySignature != isAccidentalNote && !isAccidentalRegistered)
                    {
                        _registeredAccidentals[line] = true;
                        accidentalToSet = isAccidentalNote ? keySignatureAccidental : AccidentalType.Natural;
                    }
                    else if (hasNoteAccidentalForKeySignature == isAccidentalNote && isAccidentalRegistered)
                    {
                        _registeredAccidentals.Remove(line);
                        accidentalToSet = isAccidentalNote ? keySignatureAccidental : AccidentalType.Natural;
                    }
                }
            }

            // TODO: change accidentalToSet according to note.AccidentalMode

            if (quarterBend)
            {
                switch (accidentalToSet)
                {
                case AccidentalType.Natural:
                    return(AccidentalType.NaturalQuarterNoteUp);

                case AccidentalType.Sharp:
                    return(AccidentalType.SharpQuarterNoteUp);

                case AccidentalType.Flat:
                    return(AccidentalType.FlatQuarterNoteUp);
                }
            }

            return(accidentalToSet);
        }
Ejemplo n.º 23
0
        public BeatBounds FindBeat(Beat beat)
        {
            var id = beat.Id;

            if (_beatLookup.ContainsKey(id))
            {
                return(_beatLookup[id]);
            }
            return(null);
        }
Ejemplo n.º 24
0
        public EffectBand GetBand(Voice voice, string effectId)
        {
            var id = voice.Index + "." + effectId;

            if (_bandLookup.ContainsKey(id))
            {
                return(_bandLookup[id]);
            }
            return(null);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Calculates the accidental for the given note and assignes the value to it.
        /// The new accidental type is also registered within the current scope
        /// </summary>
        /// <param name="note"></param>
        /// <param name="noteLine"></param>
        /// <returns></returns>
        public AccidentalType ApplyAccidental(Note note)
        {
            var noteValue = note.RealValue;
            var ks        = note.Beat.Voice.Bar.MasterBar.KeySignature;
            var ksi       = (ks + 7);
            var index     = (noteValue % 12);
            //var octave = (noteValue / 12);

            AccidentalType accidentalToSet = AccidentalNotes[ksi][index];

            // calculate the line where the note will be according to the accidental
            int noteLine = GetNoteLineWithAccidental(note, accidentalToSet);

            // TODO: change accidentalToSet according to note.AccidentalMode

            // if there is already an accidental registered, we check if we
            // have a new accidental
            var updateAccidental = true;

            if (note.Beat.Voice.Bar.Track.IsPercussion)
            {
                accidentalToSet = AccidentalType.None;
            }
            else if (_registeredAccidentals.ContainsKey(noteLine))
            {
                var registeredAccidental = _registeredAccidentals[noteLine];

                // we only need to do anything if we are changing the accidental
                if (registeredAccidental == accidentalToSet)
                {
                    // we set the accidental to none, as the accidental is already set by a previous note
                    accidentalToSet  = AccidentalType.None;
                    updateAccidental = false;
                }
                // check if we need naturalizing
                else if (accidentalToSet == AccidentalType.None)
                {
                    accidentalToSet = AccidentalType.Natural;
                }
            }

            if (updateAccidental)
            {
                if ((accidentalToSet == AccidentalType.None || accidentalToSet == AccidentalType.Natural))
                {
                    _registeredAccidentals.Remove(noteLine);
                }
                else
                {
                    _registeredAccidentals[noteLine] = accidentalToSet;
                }
            }

            return(accidentalToSet);
        }
Ejemplo n.º 26
0
        public override BarRendererBase Create(ScoreRenderer renderer, Bar bar, FastDictionary <string, object> additionalSettings)
        {
            var tabBarRenderer = new TabBarRenderer(renderer, bar);

            if (additionalSettings.ContainsKey("rhythm"))
            {
                tabBarRenderer.RenderRhythm = (bool)additionalSettings["rhythm"];
            }

            if (additionalSettings.ContainsKey("rhythm-height"))
            {
                tabBarRenderer.RhythmHeight = (float)additionalSettings["rhythm-height"];
            }

            if (additionalSettings.ContainsKey("rhythm-beams"))
            {
                tabBarRenderer.RhythmBeams = (bool)additionalSettings["rhythm-beams"];
            }

            return(tabBarRenderer);
        }
Ejemplo n.º 27
0
        public static Tuning GetDefaultTuningFor(int stringCount)
        {
            if (_sevenStrings == null)
            {
                Initialize();
            }

            if (_defaultTunings.ContainsKey(stringCount))
            {
                return(_defaultTunings[stringCount]);
            }
            return(null);
        }
Ejemplo n.º 28
0
        private EffectGlyph CreateNoteHeadGlyph(Note n)
        {
            var isGrace = Container.Beat.GraceType != GraceType.None;

            if (n.Beat.Voice.Bar.Staff.StaffKind == StaffKind.Percussion)
            {
                var value = n.RealValue;

                if (value <= 30 || value >= 67 || NormalKeys.ContainsKey(value))
                {
                    return(new NoteHeadGlyph(0, 0, Duration.Quarter, isGrace));
                }
                if (XKeys.ContainsKey(value))
                {
                    return(new DrumSticksGlyph(0, 0, isGrace));
                }
                if (value == 46)
                {
                    return(new HiHatGlyph(0, 0, isGrace));
                }
                if (value == 49 || value == 57)
                {
                    return(new DiamondNoteHeadGlyph(0, 0, n.Beat.Duration, isGrace));
                }
                if (value == 52)
                {
                    return(new ChineseCymbalGlyph(0, 0, isGrace));
                }
                if (value == 51 || value == 53 || value == 59)
                {
                    return(new RideCymbalGlyph(0, 0, isGrace));
                }
                return(new NoteHeadGlyph(0, 0, Duration.Quarter, isGrace));
            }
            if (n.IsDead)
            {
                return(new DeadNoteHeadGlyph(0, 0, isGrace));
            }
            if (n.Beat.GraceType == GraceType.BendGrace)
            {
                return(new NoteHeadGlyph(0, 0, Duration.Quarter, true));
            }

            if (n.HarmonicType == HarmonicType.Natural)
            {
                return(new DiamondNoteHeadGlyph(0, 0, n.Beat.Duration, isGrace));
            }

            return(new NoteHeadGlyph(0, 0, n.Beat.Duration, isGrace));
        }
        private float[] FillWorkingBuffer(bool silent)
        {
            /*Break the process loop into sections representing the smallest timeframe before the midi controls need to be updated
             * the bigger the timeframe the more efficent the process is, but playback quality will be reduced.*/
            var buffer    = new float[MicroBufferSize * MicroBufferCount * SynthConstants.AudioChannels];
            var bufferPos = 0;
            var anySolo   = _isAnySolo;

            // process in micro-buffers
            for (var x = 0; x < MicroBufferCount; x++)
            {
                // process events for first microbuffer
                if (_midiEventQueue.Length > 0)
                {
                    for (var i = 0; i < _midiEventCounts[x]; i++)
                    {
                        var m = _midiEventQueue.RemoveLast();
                        ProcessMidiMessage(m.Event);
                    }
                }

                // voice processing loop
                foreach (var voice in _voices)
                {
                    if (voice.PlayingPreset != -1)
                    {
                        var channel = voice.PlayingChannel;
                        // channel is muted if it is either explicitley muted, or another channel is set to solo but not this one.
                        var isChannelMuted = _mutedChannels.ContainsKey(channel) ||
                                             anySolo && !_soloChannels.ContainsKey(channel);

                        if (silent)
                        {
                            voice.Kill();
                        }
                        else
                        {
                            voice.Render(this, buffer, bufferPos, MicroBufferSize, isChannelMuted);
                        }
                    }
                }

                bufferPos += MicroBufferSize * SynthConstants.AudioChannels;
            }

            Platform.ClearIntArray(_midiEventCounts);
            return(buffer);
        }
Ejemplo n.º 30
0
        public int GetNoteLineForValue(int rawValue, bool searchForNote = false)
        {
            if (_appliedScoreLinesByValue.ContainsKey(rawValue))
            {
                return(_appliedScoreLinesByValue[rawValue]);
            }

            if (searchForNote && _notesByValue.ContainsKey(rawValue))
            {
                return(GetNoteLine(_notesByValue[rawValue]));
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 31
0
        dynamic IRefactorEntity.CreateNode(object node)
        {
            Parent.EnsureSchemaMigration();

            DynamicEntity entity = new DynamicEntity(this, Parser.ShouldExecute, node);

            object?key = entity.GetKey();

            if (key is null)
            {
                return(entity);
            }

            if (staticData.ContainsKey(key))
            {
                throw new PersistenceException(string.Format("A static entity with the same key already exists."));
            }

            staticData.Add(key, entity);

            return(entity);
        }