/// <summary> /// Turn off string /// </summary> /// <param name="stringId"></param> private void TurnOffString(int stringId) { MyRectangle stringRect = new MyRectangle(); switch (stringId) { case 0: stringRect = string0; break; case 1: stringRect = string1; break; case 2: stringRect = string2; break; case 3: stringRect = string3; break; } stringRect.Height = 1; stringRect.Stroke = stringRect.Fill = stringOffColor; // string played stringInfos[3 - stringId].Played = false; Invalidate(); }
public void Send(ChannelMessage message) { if (message.Command == ChannelCommand.NoteOn && message.Data1 >= LowNoteID && message.Data1 <= HighNoteID) { if (message.Data2 > 0) { if (!dicNotesOn.ContainsKey(message.Data1)) { var row = 0; var col = 0; var stringId = 0; MyRectangle stringRect = new MyRectangle(); //We look for the StringInfo matching the //note information var stringInfo = GetStringInfo(message.Data1); if (stringInfo.Rect != null) { row = stringInfo.Row; col = message.Data1 - stringInfo.Min; // Exemple E Low = 40, so 40 - 40 = 0 ie fret = 0 stringRect = stringInfo.Rect; stringId = stringInfo.Row; // paint played string stringRect.Stroke = stringRect.Fill = stringOnColor; stringRect.Height = 1; // String played stringInfos[3 - stringId].Played = true; //This border shows which note //is being played var noteOn = new Border() { Width = 28, Height = 18, BackgroundBrush = innerColor, BorderPen = outerColor, Tag = stringId, CornerRadius = 5 }; //This text block displays //the fret number var txt = new TextBlock() { Text = col.ToString(), Foreground = fontBrush, HorizontalAlignment = StringAlignment.Center, VerticalAlignment = StringAlignment.Center, //FontWeight = FontWeights.Bold, FontSize = 10 }; noteOn.Child = txt; // Add note to dictionary dicNotesOn.Add(message.Data1, noteOn); // Locate Border noteOn.Top = stringRect.Rect.Y - noteOn.Height / 2; if (col < FretLocations.Count) { noteOn.Left = FretLocations[col] - noteOn.Width; // - FretWidth; } this.Controls.Add(noteOn); noteOn.BringToFront(); Invalidate(); } } } else if (message.Data2 == 0) { if (dicNotesOn.ContainsKey(message.Data1)) { var noteOff = dicNotesOn[message.Data1]; dicNotesOn.Remove(message.Data1); this.Controls.Remove(noteOff); var stringId = (int)noteOff.Tag; TurnOffString(stringId); } } } else if (message.Command == ChannelCommand.NoteOff) { if (dicNotesOn.ContainsKey(message.Data1)) { var noteOff = dicNotesOn[message.Data1]; dicNotesOn.Remove(message.Data1); this.Controls.Remove(noteOff); var stringId = (int)noteOff.Tag; TurnOffString(stringId); } } }