private void MainForm_Load(object sender, EventArgs e) { this.Opacity = 0; this.BackgroundImageLayout = ImageLayout.Stretch; this.WindowState = FormWindowState.Maximized; this.FormBorderStyle = FormBorderStyle.None; SplashForm sf = new SplashForm(); sf.ShowDialog(); this.panel1.AutoScroll = true; this.panel1.HorizontalScroll.Enabled = true; this.panel1.VerticalScroll.Enabled = true; MidiFile midiFile = new MidiFile("E:/Mozart__Rondo_Alla_Turca.mid"); MidiOptions options = new MidiOptions(midiFile); sheetMusic1.Load(midiFile, options); float zoom = (float)sheetMusic1.Width / SheetMusic.PageWidth; sheetMusic1.SetZoom(zoom); this.Opacity = 1; }
/// <summary> /// Override to add all values from all options /// </summary> /// <returns></returns> public override string ToString() { var optionValues = new List <string> { GeolocationOptions.ToString(), MidiOptions.ToString(), NotificationsOptions.ToString(), PushOptions.ToString(), SyncXhrOptions.ToString(), MicrophoneOptions.ToString(), CameraOptions.ToString(), MagnetometerOptions.ToString(), GyroscopeOptions.ToString(), SpeakerOptions.ToString(), VibrateOptions.ToString(), FullscreenOptions.ToString(), PaymentOptions.ToString(), AccelerometerOptions.ToString(), AmbientLightSensorOptions.ToString(), AutoplayOptions.ToString(), EncryptedMediaOptions.ToString(), PictureInPictureOptions.ToString(), UsbOptions.ToString(), VrOptions.ToString() }; return(string.Join("; ", optionValues.Where(s => s.Length > 0))); }
private Clef clef; /** FAB: clef of this staff */ /** 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 staffH, int tracknum, int totaltracks) { keysigWidth = SheetMusic.KeySignatureWidth(key); this.tracknum = tracknum; this.totaltracks = totaltracks; this.staffH = staffH; // FAB //showMeasures = (options.showMeasures && tracknum == 0); showMeasures = options.showMeasures; measureLength = options.time.Measure; clef = FindClef(symbols); clefsym = new ClefSymbol(clef, 0, false); keys = key.GetSymbols(clef); this.symbols = symbols; CalculateWidth(options.scrollVert); this.Height = CalculateHeight(); this.Height = staffH; CalculateStartEndTime(); FullJustify(); }
/// <summary> /// Draw the score sheetMusic on the panel pnlScrollView /// </summary> private void DrawScore() { if (sequence1 == null) { return; } Cursor = Cursors.WaitCursor; // set options options = new MidiOptions(sequence1) { scrollVert = ScrollVert, transpose = 0, key = -1, time = sequence1.Time, }; // Create object sheetMusic sheetmusic = new SheetMusic(sequence1, options, staffHeight) { Parent = pnlScrollView, }; Cursor = Cursors.Default; }
public void ToStringTest() { var midi = MidiOptions.Create() .AddMPU401() .AddMidiDevice() .AddMidiConfig("midicfg"); var iniMidi = midi.ToString(); Assert.AreEqual(iniMidi, "[midi]\r\n\r\nmpu401=intelligent\r\nmididevice=default\r\nmidiconfig=midicfg\r\n"); }
public void LoadDictionaryTest() { var midi = new MidiOptions(); var dictionary = new Dictionary <string, object>() { { "mpu401", "uart" }, { "mididevice", "win32" }, { "midiconfig", "midicfg" } }; midi.LoadDictionary(dictionary); Assert.AreEqual(midi.MPU401, MPU401.Uart); Assert.AreEqual(midi.MidiDevice, MidiDevice.Win32); Assert.AreEqual(midi.MidiConfig, "midicfg"); }
private int ytop; /** The y pixel of the top of the staff */ #endregion Fields #region Constructors 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); bitmapBrace = Resource.Brace; clefsym = new ClefSymbol(clef, 0, false); keys = key.GetSymbols(clef); this.symbols = symbols; CalculateWidth(options.scrollVert); CalculateHeight(); CalculateStartEndTime(); FullJustify(); }
/** Given all the MusicSymbols for every track, create the staffs * for the sheet music. There are two parts to this: * * - Get the list of staffs for each track. * The staffs will be stored in trackstaffs as: * * trackstaffs[0] = { Staff0, Staff1, Staff2, ... } for track 0 * trackstaffs[1] = { Staff0, Staff1, Staff2, ... } for track 1 * trackstaffs[2] = { Staff0, Staff1, Staff2, ... } for track 2 * * - Store the Staffs in the staffs list, but interleave the * tracks as follows: * * staffs = { Staff0 for track 0, Staff0 for track1, Staff0 for track2, * Staff1 for track 0, Staff1 for track1, Staff1 for track2, * Staff2 for track 0, Staff2 for track1, Staff2 for track2, * ... } */ private List<Staff> CreateStaffs(List<MusicSymbol>[] allsymbols, KeySignature key, MidiOptions options, int measurelen) { List<Staff>[] trackstaffs = new List<Staff>[ allsymbols.Length ]; int totaltracks = trackstaffs.Length; for (int track = 0; track < totaltracks; track++) { List<MusicSymbol> symbols = allsymbols[ track ]; trackstaffs[track] = CreateStaffsForTrack(symbols, measurelen, key, options, track, totaltracks); } /* Update the EndTime of each Staff. EndTime is used for playback */ foreach (List<Staff> list in trackstaffs) { for (int i = 0; i < list.Count-1; i++) { list[i].EndTime = list[i+1].StartTime; } } /* Interleave the staffs of each track into the result array. */ int maxstaffs = 0; for (int i = 0; i < trackstaffs.Length; i++) { if (maxstaffs < trackstaffs[i].Count) { maxstaffs = trackstaffs[i].Count; } } List<Staff> result = new List<Staff>(maxstaffs * trackstaffs.Length); for (int i = 0; i < maxstaffs; i++) { foreach (List<Staff> list in trackstaffs) { if (i < list.Count) { result.Add(list[i]); } } } return result; }
/** Create a new SheetMusic control, using the given midi filename. * The options can be null. */ //public SheetMusic(string filename, MidiOptions options) { // MidiFile file = new MidiFile(filename); // init(file, options); //} /** Create a new SheetMusic control, using the given raw midi byte[] data. * The options can be null. */ //public SheetMusic(byte[] data, string title, MidiOptions options) { // MidiFile file = new MidiFile(data, title); // init(file, options); // } /** Create a new SheetMusic control. * MidiFile is the parsed midi file to display. * SheetMusic Options are the menu options that were selected. * * - Apply all the Menu Options to the MidiFile tracks. * - Calculate the key signature * - For each track, create a list of MusicSymbols (notes, rests, bars, etc) * - Vertically align the music symbols in all the tracks * - Partition the music notes into horizontal staffs */ public void Load(MidiFile file, MidiOptions options) { if (options == null) { options = new MidiOptions(file); } zoom = 1.0f; filename = file.FileName; SetColors(options.colors, options.shadeColor, options.shade2Color); pen = new Pen(Color.Black, 1); List<MidiTrack> tracks = file.ChangeMidiNotes(options); SetNoteSize(options.largeNoteSize); scrollVert = options.scrollVert; showNoteLetters= options.showNoteLetters; TimeSignature time = file.Time; if (options.time != null) { time = options.time; } if (options.key == -1) { mainkey = GetKeySignature(tracks); } else { mainkey = new KeySignature(options.key); } numtracks = tracks.Count; int lastStart = file.EndTime() + options.shifttime; /* Create all the music symbols (notes, rests, vertical bars, and * clef changes). The symbols variable contains a list of music * symbols for each track. The list does not include the left-side * Clef and key signature symbols. Those can only be calculated * when we create the staffs. */ List<MusicSymbol>[] symbols = new List<MusicSymbol> [ numtracks ]; for (int tracknum = 0; tracknum < numtracks; tracknum++) { MidiTrack track = tracks[tracknum]; ClefMeasures clefs = new ClefMeasures(track.Notes, time.Measure); List<ChordSymbol> chords = CreateChords(track.Notes, mainkey, time, clefs); symbols[tracknum] = CreateSymbols(chords, clefs, time, lastStart); } List<LyricSymbol>[] lyrics = null; if (options.showLyrics) { lyrics = GetLyrics(tracks); } /* Vertically align the music symbols */ SymbolWidths widths = new SymbolWidths(symbols, lyrics); // SymbolWidths widths = new SymbolWidths(symbols); AlignSymbols(symbols, widths); staffs = CreateStaffs(symbols, mainkey, options, time.Measure); CreateAllBeamedChords(symbols, time); if (lyrics != null) { AddLyricsToStaffs(staffs, lyrics); } /* After making chord pairs, the stem directions can change, * which affects the staff height. Re-calculate the staff height. */ foreach (Staff staff in staffs) { staff.CalculateHeight(); } braces = CreateBraceSymbols(staffs); BackColor = Color.White; SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // ��ֹ��������. SetStyle(ControlStyles.DoubleBuffer, true); }
/** Given MusicSymbols for a track, create the staffs for that track. * Each Staff has a maxmimum width of PageWidth (800 pixels). * Also, measures should not span multiple Staffs. */ private List<Staff> CreateStaffsForTrack(List<MusicSymbol> symbols, int measurelen, KeySignature key, MidiOptions options, int track, int totaltracks) { int keysigWidth = KeySignatureWidth(key); int startindex = 0; List<Staff> thestaffs = new List<Staff>(symbols.Count / 50); while (startindex < symbols.Count) { /* startindex is the index of the first symbol in the staff. * endindex is the index of the last symbol in the staff. */ int endindex = startindex; int width = keysigWidth; int maxwidth; /* If we're scrolling vertically, the maximum width is PageWidth. */ if (scrollVert) { maxwidth = SheetMusic.PageWidth; } else { maxwidth = 2000000; } while (endindex < symbols.Count && width + symbols[endindex].Width < maxwidth) { width += symbols[endindex].Width; endindex++; } endindex--; /* There's 3 possibilities at this point: * 1. We have all the symbols in the track. * The endindex stays the same. * * 2. We have symbols for less than one measure. * The endindex stays the same. * * 3. We have symbols for 1 or more measures. * Since measures cannot span multiple staffs, we must * make sure endindex does not occur in the middle of a * measure. We count backwards until we come to the end * of a measure. */ if (endindex == symbols.Count - 1) { /* endindex stays the same */ } else if (symbols[startindex].StartTime / measurelen == symbols[endindex].StartTime / measurelen) { /* endindex stays the same */ } else { int endmeasure = symbols[endindex+1].StartTime/measurelen; while (symbols[endindex].StartTime / measurelen == endmeasure) { endindex--; } } int range = endindex + 1 - startindex; if (scrollVert) { width = SheetMusic.PageWidth; } Staff staff = new Staff(symbols.GetRange(startindex, range), key, options, track, totaltracks); thestaffs.Add(staff); startindex = endindex + 1; } return thestaffs; }
/** Set the MidiFile to use. * Save the list of midi notes. Each midi note includes the note Number * and StartTime (in pulses), so we know which notes to shade given the * current pulse time. */ public void SetMidiFile(MidiFile midifile, MidiOptions options) { if (midifile == null) { notes = null; useTwoColors = false; return; } List<MidiTrack> tracks = midifile.ChangeMidiNotes(options); MidiTrack track = MidiFile.CombineToSingleTrack(tracks); notes = track.Notes; maxShadeDuration = midifile.Time.Quarter * 2; /* We want to know which track the note came from. * Use the 'channel' field to store the track. */ for (int tracknum = 0; tracknum < tracks.Count; tracknum++) { foreach (MidiNote note in tracks[tracknum].Notes) { note.Channel = tracknum; } } /* When we have exactly two tracks, we assume this is a piano song, * and we use different colors for highlighting the left hand and * right hand notes. */ useTwoColors = false; if (tracks.Count == 2) { useTwoColors = true; } showNoteLetters = options.showNoteLetters; this.Invalidate(); }