public void GetNoteId_Note_Null() { Note note = null; Assert.Throws <ArgumentNullException>( () => NoteIdUtilities.GetNoteId(note), "The method did not throw a NullReferenceException when passed a null reference."); }
public void GetNoteId_Note_ValidEmpty() { var note = new Note(new NoteName(), 1); var noteId = note.GetNoteId(); Assert.NotNull(noteId, "The NoteId is null."); Assert.AreEqual(new FourBitNumber(0), noteId.Channel, "The NoteId Channel is not the expected value."); Assert.AreEqual(new SevenBitNumber(24), noteId.NoteNumber, "The NoteId NoteNumber is not the expected value."); }
//Возвращает номер ноты в октаве public static byte NoteGetPosInOctave(Melanchall.DryWetMidi.Interaction.Note n) { byte res = 0; switch (n.NoteName) { case NoteName.C: res = 1; break; case NoteName.CSharp: res = 2; break; case NoteName.D: res = 3; break; case NoteName.DSharp: res = 4; break; case NoteName.E: res = 5; break; case NoteName.F: res = 6; break; case NoteName.FSharp: res = 7; break; case NoteName.G: res = 8; break; case NoteName.GSharp: res = 9; break; case NoteName.A: res = 10; break; case NoteName.ASharp: res = 11; break; case NoteName.B: res = 12; break; } return(res); }
public void GetNoteId_Note_ValidSet() { var note = new Note(new SevenBitNumber(2)) { Channel = new FourBitNumber(1) }; var noteId = note.GetNoteId(); Assert.NotNull(noteId, "The NoteId is null."); Assert.AreEqual(new FourBitNumber(1), noteId.Channel, "The NoteId Channel is not the expected value."); Assert.AreEqual(new SevenBitNumber(2), noteId.NoteNumber, "The NoteId NoteNumber is not the expected value."); }
public void ResetScale() { prevTime = 0; startOctave = 0; notesPlayed = 0; prevNote = null; rootNote = null; scaleInterval = 0; startTime = 0; endTime = 0; notesPlayed = 0; }
//Возвращает время нажатия клавишы public static uint GetNoteTime(Melanchall.DryWetMidi.Interaction.Note note, TempoMap tempoMap) { uint res = (uint)note.TimeAs <MetricTimeSpan>(tempoMap).Milliseconds; if (note.TimeAs <MetricTimeSpan>(tempoMap).Seconds > 0) { res += (uint)note.TimeAs <MetricTimeSpan>(tempoMap).Seconds * 1000; } if (note.TimeAs <MetricTimeSpan>(tempoMap).Minutes > 0) { res += (uint)note.TimeAs <MetricTimeSpan>(tempoMap).Minutes * 60000; } return(res); }
private MidiFile To(MusicItem data) { var midiFile = new MidiFile(); var tempoMap = midiFile.GetTempoMap(); var trackChunk = new TrackChunk(); using (var notesManager = trackChunk.ManageNotes()) { var length = LengthConverter.ConvertFrom( 2 * MusicalTimeSpan.Eighth.Triplet(), 0, tempoMap); var note = new Melanchall.DryWetMidi.Interaction.Note(NoteName.A, 4, length); notesManager.Notes.Add(note); } midiFile.Chunks.Add(trackChunk); return(midiFile); }
//Возвращает номер ноты на клавиатуре public static byte NoteGetPosOnKeyboard(Melanchall.DryWetMidi.Interaction.Note n) => n.Octave > 1 ? (byte)(NoteGetPosInOctave(n) + (n.Octave - 1) * 12 + 3) : (byte)(NoteGetPosInOctave(n));
//Возвращает аналог клавишы из левой октавы public static void LowerOctave(Melanchall.DryWetMidi.Interaction.Note n) => n.SetNoteNameAndOctave(n.NoteName, n.Octave - 1);
public FlowKeyData(Melanchall.DryWetMidi.Interaction.Note note, TempoMap tempomap) { pos = MIDIFuncs.NoteGetPosOnKeyboard(note); time = MIDIFuncs.GetNoteTime(note, tempomap); length = MIDIFuncs.GetNoteLength(note, tempomap); }
public void TestMethod() { Console.WriteLine("Testing..."); var midiFile = MidiFile.Read("C:\\Users\\trent.jones\\Documents\\midi\\test my C scales.mid"); using (NotesManager notesManager = midiFile.GetTrackChunks() // shortcut method for // Chunks.OfType<TrackChunk>() .First() .ManageNotes()) { // Get notes ordered by time NotesCollection notes = notesManager.Notes; // Get all C# notes //IEnumerable<Melanchall.DryWetMidi.Interaction.Note> cSharpNotes = notes.Where(n => n.NoteName == NoteName.C); //long prevTime = 0; //The first note is the start octave foreach (var note in notes) { notesPlayed++; if (notesPlayed == 1) { rootNote = note; startOctave = note.Octave; scaleInterval = 1; startTime = note.Time; } else if (note.NoteNumber > prevNote.NoteNumber) { playDirection = "asc"; } else if (note.NoteNumber < prevNote.NoteNumber) { playDirection = "desc"; } //Set the interval //Maybe let's wait until we have all the scales plugged in Console.WriteLine(notesPlayed + " " + note.Octave + " " + note.NoteName + "(" + note.NoteNumber + ")" + " " + (note.Time - prevTime)); prevTime = note.Time; prevNote = note; //If we're back to the root note... if (note.NoteNumber == rootNote.NoteNumber && notesPlayed > 1) { Console.WriteLine("The total time was " + (note.Time - startTime)); ResetScale(); } } // Add new note: C# of octave with number of 2 // Note: DryWetMIDI uses scientific pitch notation which means middle C is C4 //notes.Add(new Melanchall.DryWetMidi.Interaction.Note(NoteName.C, 2) //{ // Channel = (FourBitNumber)2, // Velocity = (SevenBitNumber)95 //}); } }