public bool TryGetValue(TKey key, out object value) { var incr = Interlocked.Increment(ref _locker); if (incr != 1L) { NewMethod(); } var found = _inner.TryGetValue(key, out var h); if (found) // TODO what is GC between the lines? { if (h.IsAllocated) { value = h.Target; } else { _inner.Remove(key); h.Free(); value = null; found = false; } } else { value = null; } Volatile.Write(ref _locker, 0L); return(found); }
protected override void OnUpdate() { var groupLength = m_Groups.Count; m_CachedDictionaryEventKeepIds.Clear(); // Remove automatically groups with 0 entities in it // If none are found, we remove the group from the list. // If an entity is attached to the group with the same id, we use another version of this id (a là Entity class) for (int i = 0; i != m_EntityGroup.Length; i++) { var group = m_EntityGroup.EntityGroups[i]; m_CachedDictionaryEventKeepIds[group.ReferenceId] = true; } for (int i = 0; i != m_MaxId; i++) { if (m_Groups.FastTryGet(i, out var _) && !m_CachedDictionaryEventKeepIds.FastTryGet(i, out var __)) { var group = m_Groups[i]; Debug.Log($"Group({i}, {group.Version}) was unused, so it was removed."); group.IsCreated = false; group.Version++; m_PooledGroups.Enqueue(group); m_Groups.Remove(i); } } }
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); }
/// <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); }
public void SetChannelMute(int channel, bool mute) { if (mute) { _mutedChannels[channel] = true; } else { _mutedChannels.Remove(channel); } }
public void SetChannelSolo(int channel, bool solo) { if (solo) { _soloChannels[channel] = true; } else { _soloChannels.Remove(channel); } _isAnySolo = _soloChannels.Count > 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> /// <returns></returns> public AccidentalType ApplyAccidental(Note note) { var track = note.Beat.Voice.Bar.Staff.Track; var noteValue = track.IsPercussion ? PercussionMapper.MapNoteForDisplay(note) : note.RealValue - track.DisplayTranspositionPitch; var ks = note.Beat.Voice.Bar.MasterBar.KeySignature; var ksi = (ks + 7); var index = (noteValue % 12); var accidentalToSet = AccidentalType.None; var line = RegisterNoteLine(note); if (!note.Beat.Voice.Bar.Staff.Track.IsPercussion) { // 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]; 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 return(accidentalToSet); }
void IRefactorEntity.DeleteNode(object key) { Parent.EnsureSchemaMigration(); if (key == null) { throw new ArgumentNullException("key"); } if (!Key.SystemReturnType !.IsAssignableFrom(key.GetType())) { throw new InvalidCastException(string.Format("The key for entity '{0}' is of type '{1}', but the supplied key is of type '{2}'.", Name, Key.SystemReturnType.Name, key.GetType().Name)); } if (!staticData.Remove(key)) { throw new ArgumentOutOfRangeException($"Only statically created data (via the upgrade script) can be deleted here."); } if (Parser.ShouldExecute) { DynamicEntity.Delete(this, key); } }
public void Update(ref EntityArray array) { m_Entities.Clear(); EntitySpawnCount = 0; EntityReplaceCount = 0; EntityRemovalCount = 0; var defaultEntity = new Entity(); var length = array.Length; if (NeedEntitiesList) { UnityEngine.Profiling.Profiler.BeginSample("ForLoop #1 - With entities"); for (int i = 0; i != length; i++) { Entity entity; UnityEngine.Profiling.Profiler.BeginSample("Get entities and init var"); var checkedEntity = array[i]; UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("TryGet()"); if (!m_CurrentEntities.FastTryGet(checkedEntity.Index, out entity)) { if (NeedEntitiesList) { m_Entities.Add(new EntityChangeItem() { entity = checkedEntity, wasCreated = true }); } m_CurrentEntities[checkedEntity.Index] = checkedEntity; EntitySpawnCount++; } else if (NeedToCheckReplacement) { UnityEngine.Profiling.Profiler.BeginSample("Check Version"); // The entity was replaced if (entity.Version != checkedEntity.Version) { EntityReplaceCount++; m_CurrentEntities[checkedEntity.Index] = checkedEntity; } UnityEngine.Profiling.Profiler.EndSample(); } UnityEngine.Profiling.Profiler.EndSample(); } UnityEngine.Profiling.Profiler.EndSample(); } else { UnityEngine.Profiling.Profiler.BeginSample("ForLoop #1 - Without entities"); EntitySpawnCount = length - m_LastLength; m_LastLength = length; UnityEngine.Profiling.Profiler.EndSample(); } UnityEngine.Profiling.Profiler.BeginSample("Check for removal"); if (NeedToCheckRemoval && array.Length != m_CurrentEntities.Count) { var toRemove = new NativeList <int>(Allocator.Temp); foreach (var entity in m_CurrentEntities.Values) { var exist = false; for (int i = 0; i != array.Length; i++) { if (array[i].Index == entity.Index) { exist = true; break; } } if (exist) { continue; } EntityRemovalCount++; m_Entities.Add(new EntityChangeItem() { entity = entity, wasCreated = false }); toRemove.Add(entity.Index); } for (int i = 0; i != toRemove.Length; i++) { m_CurrentEntities.Remove(toRemove[i]); } toRemove.Dispose(); } UnityEngine.Profiling.Profiler.EndSample(); }