Exemplo n.º 1
0
        public void CreateStyleRule(Style style, IUrlResolutionService urlResolver, string selection)
        {
            StyleEntry entry = new StyleEntry();

            entry.Style       = style;
            entry.UrlResolver = urlResolver;
            entry.Selection   = selection;
            entries.Add(entry);
        }
Exemplo n.º 2
0
        private PitchBendMessage GetPitchBendMessage(StyleEntry msg)
        {
            TomiSoft.RolandStyleReader.PitchWheelMessage m = (TomiSoft.RolandStyleReader.PitchWheelMessage)msg.Message;

            return(new PitchBendMessage(
                       this.Device,
                       ChannelMappings[msg.Instrument],
                       0,
                       m.TotalTime
                       ));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Runs all runCommands that are applicable for the current state.
 /// </summary>
 internal void RunCommands()
 {
     StyleEntry[] styleEntries = availableStyles.Array;
     for (int i = 0; i < availableStyles.Count; i++)
     {
         StyleEntry entry = styleEntries[i];
         if ((entry.state & currentState) != 0)
         {
             RunCommands(entry.styleRunCommand.runCommands);
         }
     }
 }
Exemplo n.º 4
0
        private NoteOnOffMessage GetNoteOnOffMessage(StyleEntry msg)
        {
            TomiSoft.RolandStyleReader.NoteMessage m = (TomiSoft.RolandStyleReader.NoteMessage)msg.Message;

            return(new NoteOnOffMessage(
                       this.Device,
                       ChannelMappings[msg.Instrument],
                       (Pitch)((m.Note < 128) ? m.Note : 1),
                       m.Velocity,
                       m.TotalTime / 120f,
                       this.clock,
                       m.Length
                       ));
        }
Exemplo n.º 5
0
        private Message ConvertMessage(StyleEntry msg)
        {
            switch (msg.Message.MessageType)
            {
            case MidiMessageType.Note:
                return(this.GetNoteOnOffMessage(msg));

            case MidiMessageType.PitchWheel:
                return(this.GetPitchBendMessage(msg));

            case MidiMessageType.ControlChange:
                return(this.GetControlChangeMessage(msg));

            default:
                return(null);
            }
        }
        private void lwMessages_DoubleClick(object sender, EventArgs e)
        {
            if (lwMessages.SelectedIndices.Count == 1)
            {
                StyleEntry entry = (StyleEntry)lwMessages.SelectedItems[0].Tag;

                switch (entry.Message.MessageType)
                {
                case MidiMessageType.Note:
                    NoteMessage         msg = (NoteMessage)entry.Message;
                    NoteEventEditDialog dlg = new NoteEventEditDialog(this.Data.Measure, msg);
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                    }
                    break;
                }
            }
        }
Exemplo n.º 7
0
        public void Highlight(Scintilla editor, int startPos, int endPos)
        {
            int length = (endPos - startPos) + 1;

            editor.StartStyling(startPos);
            editor.SetStyling(length, 0);

            var rangeEntry          = new StyleEntry(startPos, length, 0);
            var intersectingEntries = _entries.Where(r => r.InterectsWith(rangeEntry));

            foreach (StyleEntry entry in intersectingEntries)
            {
                int s = Math.Max(startPos, entry.Index);
                int e = Math.Min(entry.Index + (entry.Length - 1), endPos);
                int l = (e - s) + 1;
                editor.StartStyling(s);
                editor.SetStyling(l, entry.Style);
            }
        }
Exemplo n.º 8
0
        private Midi.ControlChangeMessage GetControlChangeMessage(StyleEntry msg)
        {
            TomiSoft.RolandStyleReader.ControlChangeMessage m = (TomiSoft.RolandStyleReader.ControlChangeMessage)msg.Message;

            Dictionary <ControlType, Control> ControlMappings = new Dictionary <ControlType, Control>()
            {
                { ControlType.Chorus, Control.ChorusLevel },
                { ControlType.Expression, Control.Expression },
                { ControlType.Pan, Control.Pan },
                { ControlType.Reverb, Control.ReverbLevel }
            };

            return(new Midi.ControlChangeMessage(
                       this.Device,
                       ChannelMappings[msg.Instrument],
                       ControlMappings[m.Control],
                       m.Value,
                       m.TotalTime
                       ));
        }
Exemplo n.º 9
0
        internal void EnterState(StyleState state)
        {
            if (state == StyleState.Normal || (currentState & state) != 0)
            {
                return;
            }

            StyleState oldState = currentState;

            currentState |= state;

            if ((containedStates & state) == 0)
            {
                return;
            }

            LightList <StylePropertyId> toUpdate = LightList <StylePropertyId> .Get();

            IStyleSystem styleSystem = element.application.styleSystem;

            StyleEntry[] styleEntries = availableStyles.Array;
            for (int i = 0; i < availableStyles.Count; i++)
            {
                StyleEntry entry = styleEntries[i];

                // if this is a state we had not been in before, mark it's properties for update
                if ((entry.state & oldState) == 0 && (entry.state & state) != 0)
                {
                    AddMissingProperties(toUpdate, entry.styleRunCommand.style);
                    RunCommands(entry.styleRunCommand.runCommands);
                }
            }

            UpdatePropertyMap(toUpdate);

            LightList <StylePropertyId> .Release(ref toUpdate);
        }
Exemplo n.º 10
0
        internal void ExitState(StyleState state)
        {
            if (state == StyleState.Normal || (currentState & state) == 0)
            {
                return;
            }

            StyleState oldState = currentState;

            currentState &= ~(state);
            currentState |= StyleState.Normal;

            if ((containedStates & state) == 0)
            {
                return;
            }

            LightList <StylePropertyId> toUpdate = LightList <StylePropertyId> .Get();

            StyleEntry[] styleEntries = availableStyles.Array;
            for (int i = 0; i < availableStyles.Count; i++)
            {
                StyleEntry entry = styleEntries[i];

                // if this a state we were in that is now invalid, mark it's properties for update
                if ((entry.state & oldState) != 0 && (entry.state & state) != 0)
                {
                    AddMissingProperties(toUpdate, entry.styleRunCommand.style);
                    RunCommands(entry.styleRunCommand.runCommands, false);
                }
            }

            UpdatePropertyMap(toUpdate);

            LightList <StylePropertyId> .Release(ref toUpdate);
        }
Exemplo n.º 11
0
		public void CreateStyleRule (Style style, IUrlResolutionService urlResolver, string selection)
		{
			StyleEntry entry = new StyleEntry ();
			entry.Style = style;
			entry.UrlResolver = urlResolver;
			entry.Selection = selection;
			entries.Add (entry);
		}
Exemplo n.º 12
0
            public bool InterectsWith(StyleEntry other)
            {
                bool result = (Index <= other.End) && (End >= other.Index);

                return(result);
            }
Exemplo n.º 13
0
        /// <summary>
        /// Call once when the server or app is started. Loads all the styles and caches baseline data for later use.
        /// </summary>
        /// <param name="onlyDefaults">if true, skip loading the styles from the DB and use Praxismapper's defaults </param>
        public static void Initialize(bool onlyDefaults = false, IMapTiles mapTiles = null)
        {
            MapTiles = mapTiles;
            List <StyleEntry> styles;

            if (onlyDefaults)
            {
                styles = Singletons.defaultStyleEntries;

                long i = 1;
                foreach (var s in styles)
                {
                    foreach (var p in s.PaintOperations)
                    {
                        p.Id = i++;
                    }
                }
            }
            else
            {
                try
                {
                    //Load TPE entries from DB for app.
                    var db = new PraxisContext();
                    styles = db.StyleEntries.Include(t => t.StyleMatchRules).Include(t => t.PaintOperations).ToList();
                    if (styles == null || styles.Count() == 0)
                    {
                        styles = Singletons.defaultStyleEntries;
                    }

                    var bitmaps = db.StyleBitmaps.ToList();
                    foreach (var b in bitmaps)
                    {
                        cachedBitmaps.Add(b.Filename, b.Data); //Actual MapTiles dll will process the bitmap, we just load it here.
                    }
                }
                catch (Exception ex)
                {
                    //The database doesn't exist, use defaults.
                    Log.WriteLog("Error initializing:" + ex.Message, Log.VerbosityLevels.Errors);
                    styles = Singletons.defaultStyleEntries;
                }
            }

            var groups = styles.GroupBy(s => s.StyleSet);

            foreach (var g in groups)
            {
                allStyleGroups.Add(g.Key, g.Select(gg => gg).OrderBy(gg => gg.MatchOrder).ToDictionary(k => k.Name, v => v));
            }

            //Default style should be transparent, matches anything (assumed other styles were checked first)
            defaultStyle = new StyleEntry()
            {
                MatchOrder      = 10000,
                Name            = "unmatched",
                StyleSet        = "mapTiles",
                PaintOperations = new List <StylePaint>()
                {
                    new StylePaint()
                    {
                        HtmlColorCode = "00000000", FillOrStroke = "fill", LineWidthDegrees = 1, LinePattern = "solid", LayerId = 101
                    }
                },
                StyleMatchRules = new List <StyleMatchRule>()
                {
                    new StyleMatchRule()
                    {
                        Key = "*", Value = "*", MatchType = "default"
                    }
                }
            };
            MapTiles.Initialize();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Determine if this StyleEntry matches or not against a Place's tags. Higher performance due to the use of a dictionary.
        /// </summary>
        /// <param name="tpe">the StyleEntry to match</param>
        /// <param name="tags">a Dictionary representing the place's tags</param>
        /// <returns>true if this rule entry matches against the place's tags, or false if not.</returns>
        public static bool MatchOnTags(StyleEntry tpe, Dictionary <string, string> tags)
        {
            bool OrMatched   = false;
            int  orRuleCount = 0;

            StyleMatchRule entry;

            //Step 1: check all the rules against these tags.
            //The * value is required for all the rules, so check it first.
            for (var i = 0; i < tpe.StyleMatchRules.Count(); i++)
            {
                entry = tpe.StyleMatchRules.ElementAt(i);

                string actualvalue = "";
                bool   isPresent   = tags.TryGetValue(entry.Key, out actualvalue);

                switch (entry.MatchType)
                {
                case "any":
                    if (!isPresent)
                    {
                        return(false);
                    }

                    if (entry.Value == "*")
                    {
                        continue;
                    }

                    if (!entry.Value.Contains(actualvalue))
                    {
                        return(false);
                    }
                    break;

                case "or":                       //Or rules don't fail early, since only one of them needs to match. Otherwise is the same as ANY logic.
                    orRuleCount++;
                    if (!isPresent || OrMatched) //Skip checking the actual value if we already matched on an OR rule.
                    {
                        continue;
                    }

                    if (entry.Value == "*" || entry.Value.Contains(actualvalue))
                    {
                        OrMatched = true;
                    }
                    break;

                case "not":
                    if (!isPresent)
                    {
                        continue;
                    }

                    if (entry.Value.Contains(actualvalue) || entry.Value == "*")
                    {
                        return(false);    //Not does not want to match this.
                    }
                    break;

                case "equals":     //for single possible values, EQUALS is slightly faster than ANY
                    if (entry.Value == "*" && isPresent)
                    {
                        continue;
                    }

                    if (!isPresent || actualvalue != entry.Value)
                    {
                        return(false);
                    }
                    break;

                case "none":
                    //never matches anything. Useful for background color or other special styles that need to exist but don't want to appear normally.
                    return(false);

                case "default":
                    //Always matches. Can only be on one entry, which is the last entry and the default color
                    return(true);
                }
            }

            //Now, we should have bailed out if any mandatory thing didn't match. Now make sure that we either had 0 OR checks or matched on any OR rule provided.
            if (OrMatched || orRuleCount == 0)
            {
                return(true);
            }

            //We did not match an OR clause, so this TPE is not a match.
            return(false);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Determine if this StyleEntry matches or not against a Place's tags.
 /// </summary>
 /// <param name="tpe">The StyleEntry to check</param>
 /// <param name="tags">the tags for a Place to use</param>
 /// <returns>true if this StyleEntry applies to this Place's tags, or false if it does not.</returns>
 public static bool MatchOnTags(StyleEntry tpe, ICollection <PlaceTags> tags)
 {
     //NOTE: this cast make this path slightly slower (.01ms), but I don't have to maintain 2 version of this functions full code.
     return(MatchOnTags(tpe, tags.ToDictionary(k => k.Key, v => v.Value)));
 }