private void Instrument_Clicked(object sender, RoutedEventArgs e)
{
int num = Convert.ToInt32(((MenuItem)sender).Tag);
canv.Children.Remove(keyLine);
WriteSettingsToFile(num);
instrument = num;
//MessageBox.Show(num.ToString());
if (num == 30 || num == 35) {
hInst = 1;
//keyLine.Height = 400;
//keyLine.Width = 53;
}
else {
hInst = 0;
keyLine.SetValue(Canvas.LeftProperty, 0.0);
keyLine.SetValue(Canvas.BottomProperty, 20.0);
Canvas.SetZIndex(keyLine, (int)90);
//keyLine.Height = 3;
//keyLine.Width = 1280;
}
// remove the fingering rectangles from the canvas right now, because after they are re-initialized we'll
// lose track of the ones already on the canvas
try {
for (int i = 0; i < r_instrument.Length; i++) {
canv.Children.Remove(r_instrument[i]);
canv.Children.Remove(tb_instrument[i]);
canv.Children.Remove(r_separators[i]);
}
canv.Children.Remove(r_separators[r_separators.Length - 1]);
} catch (NullReferenceException nr_e) { }
if (num == 35 || num == 41) {
r_instrument = new Border[4];
tb_instrument = new TextBlock[4];
r_separators = new Rectangle[5];
}
else if (num == 74) {
r_instrument = new Border[11];
tb_instrument = new TextBlock[11];
r_separators = new Rectangle[12];
}
else if (num == 30) {
r_instrument = new Border[6];
tb_instrument = new TextBlock[6];
r_separators = new Rectangle[7];
}
for (int i = 0; i < r_instrument.Length; i++) {
r_instrument[i] = new Border{ };
r_separators[i] = new Rectangle { };
tb_instrument[i] = new TextBlock { };
r_instrument[i].Visibility = Visibility.Hidden;
r_separators[i].Visibility = Visibility.Hidden;
tb_instrument[i].Visibility = Visibility.Hidden;
}
r_separators[r_separators.Length - 1] = new Rectangle { };
r_separators[r_separators.Length - 1].Visibility = Visibility.Hidden;
keyLine.Fill = new SolidColorBrush(Color.FromRgb(51, 51, 51));
canv.Children.Add(keyLine);
// this has been moved from updateFingeringDisplay --------------------
// if violin
if (num == 41) {
int margin = 300;
int padding = 30;
for (int i = 0; i < r_instrument.Length; i++) {
tb_instrument[i].Height = 50;
tb_instrument[i].Width = 50;
r_instrument[i].Height = 50;
r_instrument[i].Width = 46;
tb_instrument[i].SetValue(Canvas.LeftProperty, (margin + ((i + 1) * (r_instrument[i].Width + (padding)))));
r_instrument[i].SetValue(Canvas.LeftProperty, (margin + ((i + 1) * (r_instrument[i].Width + (padding)))));
tb_instrument[i].SetValue(Canvas.TopProperty, (double)630);
r_instrument[i].SetValue(Canvas.TopProperty, (double)630);
switch (i) {
case 0:
r_instrument[i].Background = new SolidColorBrush(tint[6]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[6]);
break;
case 1:
r_instrument[i].Background = new SolidColorBrush(tint[2]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[2]);
break;
case 2:
r_instrument[i].Background = new SolidColorBrush(tint[0]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[0]);
break;
case 3:
r_instrument[i].Background = new SolidColorBrush(tint[10]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[10]);
break;
}
}
} // end if (num == 41)
// if guitar
else if (num >= 25 && num <= 32) {
int margin = 170;
int padding = 10;
for (int i = 0; i < r_instrument.Length; i++) {
tb_instrument[i].Height = 50;
tb_instrument[i].Width = 50;
r_instrument[i].Height = 46;
r_instrument[i].Width = 60;
tb_instrument[i].SetValue(Canvas.TopProperty, (double)(margin + (i * (r_instrument[i].Height + padding)) - 7));
tb_instrument[i].SetValue(Canvas.LeftProperty, (double)5);
r_instrument[i].SetValue(Canvas.TopProperty, (double)(margin + (i * (r_instrument[i].Height + padding))));
switch (i) {
case 5:
r_instrument[i].Background = new SolidColorBrush(tint[6]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[6]);
tb_instrument[i].Foreground = new SolidColorBrush(border[6]);
break;
case 4:
r_instrument[i].Background = new SolidColorBrush(tint[2]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[2]);
tb_instrument[i].Foreground = new SolidColorBrush(border[2]);
break;
case 3:
r_instrument[i].Background = new SolidColorBrush(tint[0]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[0]);
tb_instrument[i].Foreground = new SolidColorBrush(border[0]);
break;
case 2:
r_instrument[i].Background = new SolidColorBrush(tint[10]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[10]);
tb_instrument[i].Foreground = new SolidColorBrush(border[10]);
break;
case 1:
r_instrument[i].Background = new SolidColorBrush(tint[9]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[9]);
tb_instrument[i].Foreground = new SolidColorBrush(border[9]);
break;
case 0:
r_instrument[i].Background = new SolidColorBrush(tint[8]);
r_instrument[i].BorderBrush = new SolidColorBrush(border[8]);
tb_instrument[i].Foreground = new SolidColorBrush(border[8]);
break;
}
}
for (int i = 0; i < r_separators.Length; i++) {
r_separators[i].Height = 8;
r_separators[i].Width = 8;
r_separators[i].Fill = new SolidColorBrush(Color.FromRgb(250, 250, 250));
r_separators[i].SetValue(Canvas.TopProperty, (double)(margin + (i * (r_instrument[1].Height + padding))) - 9);
}
} // end else if (num >= 25 && num <= 32)
// -------------------------------------------------------
for (int i = 0; i < r_instrument.Length; i++) {
canv.Children.Add(tb_instrument[i]);
canv.Children.Add(r_instrument[i]);
canv.Children.Add(r_separators[i]);
Canvas.SetZIndex(tb_instrument[i], (int)99);
Canvas.SetZIndex(r_instrument[i], (int)98);
}
canv.Children.Add(r_separators[r_separators.Length - 1]);
}