/// <summary> /// Initializes a new instance of the <see cref="VisualNode"/> class with random Position, speed and direction. /// </summary> /// <param name="rand">The rand.</param> /// <param name="canvas">The canvas.</param> public VisualNode(Random rand, Canvas canvas) { this.rand = rand; // choose a random position this.X = rand.Next(this.NodeSizeMax(), (int)canvas.Width - this.NodeSizeMax()); this.Y = rand.Next(this.NodeSizeMax(), (int)canvas.Height - this.NodeSizeMax()); this.CurrentX = this.X; this.CurrentY = this.Y; this.Connectedness = 0; //create a new musical note object this.noteNode = new NoteControl.Note(); //add the musical note to the canvas canvas.Children.Add(this.noteNode); //set the note's z-index to be 10 Canvas.SetZIndex(this.noteNode, 10); #region Commented out Node Garden code //CODE BELOW AND ALL RELATED LINES COMMENTED OUT FROM NOTE GARDEN AS THE MUSICAL NOTE DOES NOT HAVE CENTER/OUTLINE/SHADOW1/SHADOW2 ELEMENTS // create ellipses that make the node, it's outline and 2 shadows //this.Center = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(105, 255, 255, 255)) }; //this.Outline = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) }; //this.Shadow1 = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)) }; //this.Shadow2 = new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(60, 255, 255, 255)) }; //this.Center = new Ellipse { Fill = new SolidColorBrush(Colors.Black) }; //this.Outline = new Ellipse { Fill = new SolidColorBrush(Colors.Black) }; //this.Shadow1 = new Ellipse { Fill = new SolidColorBrush(Colors.Black) }; //this.Shadow2 = new Ellipse { Fill = new SolidColorBrush(Colors.Black) }; // add the shapes to the canvas UIElement //canvas.Children.Add(this.Center); //canvas.Children.Add(this.Outline); //canvas.Children.Add(this.Shadow1); //canvas.Children.Add(this.Shadow2); // set the ZIndex so the Center is in front of the outline and shadows //Canvas.SetZIndex(this.Center, 10); //Canvas.SetZIndex(this.Outline, 9); //Canvas.SetZIndex(this.Shadow1, 8); //Canvas.SetZIndex(this.Shadow2, 7); #endregion //get a random note int noteIndex = rand.Next(65, 73); //convert int to char char note = (char)noteIndex; if (note != 'H') //if the returned value is 'H', assign Middle C { try { //parse the value of 'note' into a SoundNotes enum value this.Note = (SoundNotes)Enum.Parse(typeof(SoundNotes), note.ToString(), true); } catch { //if there was an issue with the note parsing, just assign middle C this.Note = SoundNotes.MiddleC; } } else { this.Note = SoundNotes.MiddleC; } }
/// <summary> /// Play the sound of the note provided /// </summary> /// <param name="sn">Note to play</param> /// <param name="connectionStrength">Strength of the connections at this node</param> private void PlaySound(SoundNotes sn, float connectionStrength = 0.0f) { //ConnectionStrength could be used with SoundEffectInstances to change the pitch/volume depending on strength //e.g. allNotes[1].Pitch = Math.Min(connectionStrength, 1.0f); switch (sn) { //simply play the relevant index from the allNotes array case SoundNotes.A: Play(1); break; case SoundNotes.B: Play(2); break; case SoundNotes.C: Play(3); break; case SoundNotes.D: Play(4); break; case SoundNotes.E: Play(5); break; case SoundNotes.F: Play(6); break; case SoundNotes.G: Play(7); break; case SoundNotes.MiddleC: Play(0); break; default: Play(0); break; } }