private void Grid001_PreviewMouseDown(object sender, MouseButtonEventArgs e) { Point p = Mouse.GetPosition(Grid001); musicBar thisBar = createMusicBar((int)p.X, A4); ((Grid)sender).Children.Add(thisBar); barList.Add(thisBar); }
private musicBar createMusicBar(int x, float hz) { musicBar thisBar = new musicBar(); thisBar.Margin = new Thickness(x, 0, 0, 0); thisBar.startTime = x; thisBar.hz = hz; thisBar.vibrato = (short)vibratoSlider.Value; thisBar.setWaveType(waveCombo.SelectedIndex); thisBar.vibratoIntensity = (short)vibratoIntensitySlider.Value; thisBar.volume = (short)volumeSlider.Value; return(thisBar); }
private void editBar(object sender, MouseButtonEventArgs e) { musicBar mb = ((musicBar)sender); DependencyObject parentObject = VisualTreeHelper.GetParent((musicBar)sender); Grid parent = (Grid)parentObject; deleteButton.Visibility = Visibility.Visible; saveButton.Visibility = Visibility.Visible; volumeSlider.Value = mb.volume; vibratoSlider.Value = mb.vibrato; vibratoIntensitySlider.Value = mb.vibratoIntensity; waveCombo.SelectedIndex = mb.waveType - 1; publicBar = mb; publicBarParent = parent; if (newestBar != null && newestBar != null) { RemoveBar(newestBar, newestBarParent); } newestBar = null; newestBarParent = null; }
private void Grid108_PreviewMouseDown(object sender, MouseButtonEventArgs e) { Point p = Mouse.GetPosition(Grid108); musicBar thisBar = createMusicBar((int)p.X, CN0); ((Grid)sender).Children.Add(thisBar); newestBar = thisBar; newestBarParent = (Grid)sender; thisBar.PreviewMouseDown += new MouseButtonEventHandler(editBar); barList.Add(thisBar); }
private void RemoveBar(musicBar mb, Grid parent) { parent.Children.Remove(mb); barList.Remove(mb); }
public void playSound(musicBar mb) { float frequency = mb.hz; int type = mb.waveType; int multi = mb.timeUnits; short volume = mb.volume; short vibrato = mb.vibrato; short vibratoIntensity = mb.vibratoIntensity; int divi = 50; int amplitude = ((short.MaxValue / 100) * volume); short[] wave = new short[(SAMPLE_RATE * multi) / divi]; byte[] binarywave = new byte[(SAMPLE_RATE * multi) / divi * sizeof(short)]; switch (type) { case 1: // Sine wave = createSine(wave, multi, divi, amplitude, frequency, vibrato, vibratoIntensity); break; case 2: // Square wave = createSquare(wave, multi, divi, amplitude, frequency, vibrato, vibratoIntensity); break; case 3: // sinetooth wave = createSineTooth(wave, multi, divi, amplitude, frequency, vibrato, vibratoIntensity); break; case 4: // inverted sinetooth wave = createSineToothReversed(wave, multi, divi, amplitude, frequency, vibrato, vibratoIntensity); break; case 5: //noise wave = createNoise(wave, multi, divi, amplitude, frequency); break; case 6: break; case 7: break; default: break; } Buffer.BlockCopy(wave, 0, binarywave, 0, wave.Length * sizeof(short)); using (MemoryStream memorystream = new MemoryStream()) using (BinaryWriter binarywriter = new BinaryWriter(memorystream)) { short blockAlign = BITS_PER_SAMPLE / 8; int subChunkTwoSize = ((SAMPLE_RATE * multi) / divi) * blockAlign; binarywriter.Write(new[] { 'R', 'I', 'F', 'F' }); binarywriter.Write(36 + subChunkTwoSize); binarywriter.Write(new[] { 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ' }); binarywriter.Write(16); binarywriter.Write((short)1); binarywriter.Write((short)1); binarywriter.Write(SAMPLE_RATE); binarywriter.Write(SAMPLE_RATE * blockAlign); binarywriter.Write(blockAlign); binarywriter.Write(BITS_PER_SAMPLE); binarywriter.Write(new[] { 'd', 'a', 't', 'a' }); binarywriter.Write(subChunkTwoSize); binarywriter.Write(binarywave); memorystream.Position = 0; new SoundPlayer(memorystream).Play(); } }