/** The MidiFile and/or SheetMusic has changed. Stop any playback sound, * and store the current midifile and sheet music. */ public void SetMidiFile(MidiFile file, MidiOptions opt, SheetMusic s) { /* If we're paused, and using the same midi file, redraw the * highlighted notes. */ if ((file == midifile && midifile != null && playstate == paused)) { options = opt; sheet = s; sheet.ShadeNotes((int)currentPulseTime, (int)-10, false); /* We have to wait some time (200 msec) for the sheet music * to scroll and redraw, before we can re-shade. */ Timer redrawTimer = new Timer(); redrawTimer.Interval = 200; redrawTimer.Tick += new EventHandler(ReShade); redrawTimer.Enabled = true; redrawTimer.Start(); } else { this.Stop(null, null); midifile = file; options = opt; sheet = s; } this.DeleteSoundFile(); }
private int measureLength; /** The time (in pulses) of a measure */ /** Create a new staff with the given list of music symbols, * and the given key signature. The clef is determined by * the clef of the first chord symbol. The track number is used * to determine whether to join this left/right vertical sides * with the staffs above and below. The SheetMusicOptions are used * to check whether to display measure numbers or not. */ public Staff(List <MusicSymbol> symbols, KeySignature key, MidiOptions options, int tracknum, int totaltracks) { keysigWidth = SheetMusic.KeySignatureWidth(key); this.tracknum = tracknum; this.totaltracks = totaltracks; showMeasures = (options.showMeasures && tracknum == 0); measureLength = options.time.Measure; Clef clef = FindClef(symbols); clefsym = new ClefSymbol(clef, 0, false); keys = key.GetSymbols(clef); this.symbols = symbols; CalculateWidth(options.scrollVert); CalculateHeight(); CalculateStartEndTime(); FullJustify(); }
/** Create a new MidiPlayer, displaying the play/stop buttons, the * speed bar, and volume bar. The midifile and sheetmusic are initially null. */ public MidiPlayer() { this.Font = new Font("Arial", 10, FontStyle.Bold); loadButtonImages(); int buttonheight = this.Font.Height * 2; this.midifile = null; this.options = null; this.sheet = null; playstate = stopped; startTime = DateTime.Now.TimeOfDay; startPulseTime = 0; currentPulseTime = 0; prevPulseTime = -10; errormsg = new StringBuilder(256); ToolTip tip; /* Create the rewind button */ rewindButton = new Button(); rewindButton.Parent = this; rewindButton.Image = rewindImage; rewindButton.ImageAlign = ContentAlignment.MiddleCenter; rewindButton.Size = new Size(buttonheight, buttonheight); rewindButton.Location = new Point(buttonheight / 2, buttonheight / 2); rewindButton.Click += new EventHandler(Rewind); tip = new ToolTip(); tip.SetToolTip(rewindButton, "Rewind"); /* Create the play button */ playButton = new Button(); playButton.Parent = this; playButton.Image = playImage; playButton.ImageAlign = ContentAlignment.MiddleCenter; playButton.Size = new Size(buttonheight, buttonheight); playButton.Location = new Point(buttonheight / 2, buttonheight / 2); playButton.Location = new Point(rewindButton.Location.X + rewindButton.Width + buttonheight / 2, rewindButton.Location.Y); playButton.Click += new EventHandler(PlayPause); playTip = new ToolTip(); playTip.SetToolTip(playButton, "Play"); /* Create the stop button */ stopButton = new Button(); stopButton.Parent = this; stopButton.Image = stopImage; stopButton.ImageAlign = ContentAlignment.MiddleCenter; stopButton.Size = new Size(buttonheight, buttonheight); stopButton.Location = new Point(playButton.Location.X + playButton.Width + buttonheight / 2, playButton.Location.Y); stopButton.Click += new EventHandler(Stop); tip = new ToolTip(); tip.SetToolTip(stopButton, "Stop"); /* Create the fastFwd button */ fastFwdButton = new Button(); fastFwdButton.Parent = this; fastFwdButton.Image = fastFwdImage; fastFwdButton.ImageAlign = ContentAlignment.MiddleCenter; fastFwdButton.Size = new Size(buttonheight, buttonheight); fastFwdButton.Location = new Point(stopButton.Location.X + stopButton.Width + buttonheight / 2, stopButton.Location.Y); fastFwdButton.Click += new EventHandler(FastForward); tip = new ToolTip(); tip.SetToolTip(fastFwdButton, "Fast Forward"); /* Create the Speed bar */ Label speedLabel = new Label(); speedLabel.Parent = this; speedLabel.Text = "Speed: "; speedLabel.TextAlign = ContentAlignment.MiddleRight; speedLabel.Height = buttonheight; speedLabel.Width = buttonheight * 2; speedLabel.Location = new Point(fastFwdButton.Location.X + fastFwdButton.Width + buttonheight / 2, fastFwdButton.Location.Y); speedBar = new TrackBar(); speedBar.Parent = this; speedBar.Minimum = 1; speedBar.Maximum = 100; speedBar.TickFrequency = 10; speedBar.TickStyle = TickStyle.BottomRight; speedBar.LargeChange = 10; speedBar.Value = 100; speedBar.Width = buttonheight * 5; speedBar.Location = new Point(speedLabel.Location.X + speedLabel.Width + 2, speedLabel.Location.Y); tip = new ToolTip(); tip.SetToolTip(speedBar, "Adjust the speed"); /* Create the Volume bar */ Label volumeLabel = new Label(); volumeLabel.Parent = this; volumeLabel.Image = volumeImage; volumeLabel.ImageAlign = ContentAlignment.MiddleRight; volumeLabel.Height = buttonheight; volumeLabel.Width = buttonheight * 2; volumeLabel.Location = new Point(speedBar.Location.X + speedBar.Width + buttonheight / 2, speedBar.Location.Y); volumeBar = new TrackBar(); volumeBar.Parent = this; volumeBar.Minimum = 1; volumeBar.Maximum = 100; volumeBar.TickFrequency = 10; volumeBar.TickStyle = TickStyle.BottomRight; volumeBar.LargeChange = 10; volumeBar.Value = 100; volumeBar.Width = buttonheight * 5; volumeBar.Location = new Point(volumeLabel.Location.X + volumeLabel.Width + 2, volumeLabel.Location.Y); volumeBar.Scroll += new EventHandler(ChangeVolume); tip = new ToolTip(); tip.SetToolTip(volumeBar, "Adjust the volume"); Height = buttonheight * 2; /* Initialize the timer used for playback, but don't start * the timer yet (enabled = false). */ timer = new Timer(); timer.Enabled = false; timer.Interval = 100; /* 100 millisec */ timer.Tick += new EventHandler(TimerCallback); tempSoundFile = ""; }
private SheetMusic sheetmusic; /** Used to get colors and other options */ /** Create a new Chord Symbol from the given list of midi notes. * All the midi notes will have the same start time. Use the * key signature to get the white key and accidental symbol for * each note. Use the time signature to calculate the duration * of the notes. Use the clef when drawing the chord. */ public ChordSymbol(List <MidiNote> midinotes, KeySignature key, TimeSignature time, Clef c, SheetMusic sheet) { int len = midinotes.Count; int i; hastwostems = false; clef = c; sheetmusic = sheet; starttime = midinotes[0].StartTime; endtime = midinotes[0].EndTime; for (i = 0; i < midinotes.Count; i++) { if (i > 1) { if (midinotes[i].Number < midinotes[i - 1].Number) { throw new System.ArgumentException("Chord notes not in increasing order by number"); } } endtime = Math.Max(endtime, midinotes[i].EndTime); } notedata = CreateNoteData(midinotes, key, time); accidsymbols = CreateAccidSymbols(notedata, clef); /* Find out how many stems we need (1 or 2) */ NoteDuration dur1 = notedata[0].duration; NoteDuration dur2 = dur1; int change = -1; for (i = 0; i < notedata.Length; i++) { dur2 = notedata[i].duration; if (dur1 != dur2) { change = i; break; } } if (dur1 != dur2) { /* We have notes with different durations. So we will need * two stems. The first stem points down, and contains the * bottom note up to the note with the different duration. * * The second stem points up, and contains the note with the * different duration up to the top note. */ hastwostems = true; stem1 = new Stem(notedata[0].whitenote, notedata[change - 1].whitenote, dur1, Stem.Down, NotesOverlap(notedata, 0, change) ); stem2 = new Stem(notedata[change].whitenote, notedata[notedata.Length - 1].whitenote, dur2, Stem.Up, NotesOverlap(notedata, change, notedata.Length) ); } else { /* All notes have the same duration, so we only need one stem. */ int direction = StemDirection(notedata[0].whitenote, notedata[notedata.Length - 1].whitenote, clef); stem1 = new Stem(notedata[0].whitenote, notedata[notedata.Length - 1].whitenote, dur1, direction, NotesOverlap(notedata, 0, notedata.Length) ); stem2 = null; } /* For whole notes, no stem is drawn. */ if (dur1 == NoteDuration.Whole) { stem1 = null; } if (dur2 == NoteDuration.Whole) { stem2 = null; } width = MinWidth; }