//Note[] notes; public void triggerEvent(NoteEvent ne) { switch (ne.eventType) { case NoteEventType.NoteOn: NoteOn(ne.message); break; case NoteEventType.NoteOff: NoteOff(ne.message); //notes[ne.message.pitch].Stop(); break; } }
public void ProcessOffNote(NoteEvent note) { if (!this.PerformanceUp || !this.PerformerEnabled) { return; } if (hotkeys.GetKeybindFromNoteByte(note.note) is FFXIVKeybindDat.Keybind keybind) { if (WantsHold) { hook.SendKeybindUp(keybind); } } }
public static ProcessResultArray <Clip> Apply(TakeOptions options, params Clip[] clips) { var resultClips = new Clip[clips.Length]; // Normalize take values (typical input range: 1 - N, while 0 - N is used internally) for (var ix = 0; ix < options.TakeCounts.Length; ix++) { options.TakeCounts[ix]--; } var i = 0; foreach (var clip in clips) { var resultClip = new Clip(clips[i].Length, clips[i].IsLooping); decimal currentPos = 0; var noteIx = 0; var currentTake = options.TakeCounts[0]; var takeIx = 0; // We want to keep the length of the newly created clip approximately equal to the original, therefore we keep // going until we have filled at least the same length as the original clip while (currentPos < resultClip.Length) { if (currentTake == 0) { if (noteIx >= clip.Count) { noteIx %= clip.Count; } var note = new NoteEvent(clip.Notes[noteIx]) { Start = currentPos }; currentPos += clip.DurationUntilNextNote(noteIx); resultClip.Add(note); currentTake = options.TakeCounts[++takeIx % options.TakeCounts.Length]; } else { currentTake--; } noteIx++; } resultClips[i] = resultClip; i++; } return(new ProcessResultArray <Clip>(resultClips)); }
/// <summary> /// Send a note midi message. /// </summary> /// <param name="channel"></param> /// <param name="note"></param> /// <param name="velocity"></param> public void SendNote(int channel, int note, int velocity) { if (_mdev != null) { lock (_lock) { NoteEvent evt = new NoteEvent(0, channel, velocity > 0 ? MidiCommandCode.NoteOn : MidiCommandCode.NoteOff, note, velocity); int msg = evt.GetAsShortMessage(); _mdev.Send(msg); } } }
public void ProcessOnNote(NoteEvent note) { foreach (Control ctl in PerformerLayout.Controls) { BmpLocalPerformer performer = (ctl as BmpLocalPerformer); if (performer != null && performer.UiEnabled && performer.PerformerEnabled) { if (note.trackNum == performer.TrackNum) { int po = SequencerReference.GetTrackPreferredOctaveShift(note.track); note.note = NoteHelper.ApplyOctaveShift(note.origNote, performer.OctaveNum + po); performer.ProcessOnNote(note); } } } }
public void RecordNoteEvent(NoteEvent e) { var queue = KeyEvents[e.NoteNumber]; if (queue.Count == 0) { HitMiss += 1; return; } var(eventType, eventTime) = queue.Peek(); if (eventType == e.EventType) { var error = _song.CurrentTime - eventTime; // Ignore way early events if (error < -HitBad * 2) { return; } var window = Math.Abs(error); if (window < Settings.HitBadMicros) { var marker = new HitMarker { Error = (int)error, Time = _song.CurrentTime }; lock (HitMarkers) HitMarkers.Enqueue(marker); if (window < Settings.HitPerfectMicros) { HitPerfect++; } else if (window < Settings.HitOkayMicros) { HitOkay++; } else { HitBad++; } } else { HitMiss++; } queue.Dequeue(); } }
// TODO: Add option to cut overlapping events, so that more of the original clip is preserved public static ProcessResultArray <Clip> Apply(params Clip[] clips) { var resultClips = ClipUtilities.CreateEmptyPlaceholderClips(clips); for (var i = 0; i < clips.Length; i++) { var clip = clips[i]; var resultClip = resultClips[i]; foreach (var note in clip.Notes) { var newNote = new NoteEvent(note); AddNoteCutting(resultClip, newNote); } } return(Filter.Apply(new FilterOptions(), resultClips)); }
public void PlayNote(int noteNumber) { int channel = 0; NoteEvent note = _notesOn.FirstOrDefault(n => n.NoteNumber == noteNumber && n.Channel == channel); if (note == null) { note = new NoteEvent(channel, noteNumber); _notesOn.Add(note); _midiOut.Send(note.GetOnEvent(), 0, 3, 0); } else { _midiOut.Send(note.GetOffEvent(), 0, 3, 0); _midiOut.Send(note.GetOnEvent(), 0, 3, 0); } }
void ReleaseFM(NoteEvent non) { Parallel.For(0, chs, (i) => { if (atk[i] == null) { return; } if (non.Channel == atk[i].Channel && non.NoteNumber == atk[i].NoteNumber) { atk[i] = null; time[i] = 0; vel[i] = 0; synth[i].Release(); return; } }); }
private void OnMidiMessage(object sender, MidiInMessageEventArgs evt) { if (evt.MidiEvent.CommandCode != MidiCommandCode.NoteOn || evt.MidiEvent.CommandCode == MidiCommandCode.NoteOff) { return; // Ignore non note events } NoteEvent noteEvent = evt.MidiEvent as NoteEvent; string noteName = MidiUtils.GetNoteNameFromMidiNoteNumber(noteEvent.NoteNumber); if (noteEvent.Velocity != 0 && evt.MidiEvent.CommandCode == MidiCommandCode.NoteOn) { _onNoteOnListener(noteName, noteEvent.Velocity); } else { _onNoteOffListener(noteName); } }
// Simple algorithm for finding nearest note in a list of note events public static int FindNearestNotePitchInSet(NoteEvent needle, SortedList <NoteEvent> haystack) { int nearestIndex = 0; int?nearestDelta = null; for (int i = 0; i < haystack.Count; i++) { int needlePitch = needle.Pitch % 12; int haystackPitch = haystack[i].Pitch % 12; int currentDelta = Math.Min(Math.Abs(needlePitch - haystackPitch), Math.Abs(needlePitch - 12 - haystackPitch)); if (nearestDelta == null || currentDelta < nearestDelta) { nearestDelta = currentDelta; nearestIndex = i; } } return(haystack[nearestIndex].Pitch); }
public static MidiEventCollection transpose(MidiEventCollection m, int i) { // Loop through each track in the MidiEventCollection);) for (int track = 0; track < m.Tracks; track++) { // For every MidiEvent in that track...);) foreach (MidiEvent e in m[track]) { // This is where we can do some work. // Check the CommandCode. // Here, we are interested in NoteOn messages); if (e.CommandCode == MidiCommandCode.NoteOn) { if (e is NoteOnEvent) { // We found one. Let's cast to the subclass. NoteOnEvent n = (NoteOnEvent)e; // As long as there is a corresponding off event... if (n.OffEvent != null) { // This is a valid note-on! // Transpose by incrementing by i n.NoteNumber += i; } } else { if (e is NoteEvent) { NoteEvent ne = (NoteEvent)e; ne.NoteNumber += i; } } } } } // Return the transposed data. return(m); }
public static ProcessResultArray <Clip> Apply(QuantizeOptions options, params Clip[] clips) { var maxLen = clips.Max(x => x.Length); if (options.By != null) { if (options.By.Length < maxLen) { ClipUtilities.EnlargeClipByLooping(options.By, maxLen); } options.Divisions = options.By.Notes.Select(x => x.Start).Distinct().ToArray(); } else { var currentPos = 0m; var quantizePositions = new List <decimal>(); var i = 0; while (currentPos <= maxLen) { quantizePositions.Add(currentPos); currentPos += options.Divisions[i % options.Divisions.Length]; i++; } options.Divisions = quantizePositions.ToArray(); } options.Amount = Math.Clamp(options.Amount, 0, 1); var resultClips = new Clip[clips.Length]; for (var i = 0; i < clips.Length; i++) { var clip = clips[i]; var resultClip = new Clip(clip.Length, clip.IsLooping); foreach (var note in clip.Notes) { var constrainedNote = new NoteEvent(note); var newStart = ClipUtilities.FindNearestNoteStartInDecimalSet(note, options.Divisions); constrainedNote.Start += (newStart - constrainedNote.Start) * options.Amount; resultClip.Add(constrainedNote); } resultClips[i] = resultClip; } return(new ProcessResultArray <Clip>(resultClips)); }
private void OffMidiVoice(Object o, NoteEvent offNote) { if (LocalOrchestra.OrchestraEnabled) { LocalOrchestra.ProcessOffNote(offNote); return; } if (Player.Status == PlayerStatus.Conducting) { return; } if (!FFXIV.IsPerformanceReady()) { return; } if (offNote.track != null) { if (offNote.track != Player.Player.LoadedTrack) { return; } } if (WantsSlow) { return; } if (!FFXIV.memory.ChatInputOpen) { if (WantsHold) { if (FFXIV.hotkeys.GetKeybindFromNoteByte(offNote.note) is FFXIVKeybindDat.Keybind keybind) { FFXIV.hook.SendKeybindUp(keybind); } chordNotes.OffKey(offNote); } } }
public bool OnKey(T t) { int chordDetection = Properties.Settings.Default.ChordDetectionDelay; bool tooFastChord = (Math.Abs(this.Tick - MaxTick) < chordDetection); noteTimers.SetTimestamp(t, this.Tick); if (!tooFastChord) { tickNoteCount = 0; } else { tickNoteCount++; } // Chord simulation if (tooFastChord && (tickNoteCount >= 1)) { //Console.WriteLine(string.Format("{0} - {1} = {2}", this.Tick, MaxTick, tooFastChord)); if (noteTimers.TryRemoveTimer(t, out Timer delayedTimer)) { delayedTimer.Dispose(); } delayedTimer = new Timer { Interval = (tickNoteCount * 100), Enabled = true, }; delayedTimer.Elapsed += delegate { if (noteTimers.TryRemoveTimer(t, out Timer timer)) { timer.Dispose(); NoteEvent?.Invoke(this, t); } }; noteTimers.SetTimer(t, delayedTimer); return(true); } return(false); }
public static decimal FindNearestNoteStartInDecimalSet(NoteEvent needle, decimal[] haystack) { var nearestIndex = 0; decimal?nearestDelta = null; for (int i = 0; i < haystack.Length; i++) { if (nearestDelta == null) { nearestDelta = Math.Abs(needle.Start - haystack[i]); } decimal currentDelta = Math.Abs(needle.Start - haystack[i]); if (currentDelta < nearestDelta) { nearestDelta = currentDelta; nearestIndex = i; } } return(haystack[nearestIndex]); }
public static decimal FindNearestNoteStartInSet(NoteEvent needle, SortedList <NoteEvent> haystack) { var nearestIndex = 0; decimal?nearestDelta = null; for (int i = 0; i < haystack.Count; i++) { if (nearestDelta == null) { nearestDelta = Math.Abs(needle.Start - haystack[i].Start); } decimal currentDelta = Math.Abs(needle.Start - haystack[i].Start); if (currentDelta < nearestDelta) { nearestDelta = currentDelta; nearestIndex = i; } } return(haystack[nearestIndex].Start); }
void TriggerEvent(INoteEventListener listener, NoteEvent ev) { switch (ev.type) { case NoteEvent.Type.Start: listener.OnNoteStart(); break; case NoteEvent.Type.Update: listener.OnNoteUpdate(ev.progress); break; case NoteEvent.Type.End: listener.OnNoteEnd(); break; default: break; } }
public static void AddNoteCutting(Clip clip, NoteEvent noteToAdd) { var collidingNotes = clip.Notes.Where(x => x.Pitch == noteToAdd.Pitch && noteToAdd.StartsInsideInterval(x.Start, x.End)).ToArray(); if (collidingNotes.Length > 0) { foreach (var note in collidingNotes) { if (note.Start == noteToAdd.Start && noteToAdd.Duration > note.Duration) // largest note wins in the case of a collision { clip.Notes.RemoveAt(clip.Notes.IndexOf(note)); } else { note.Duration = noteToAdd.Start - note.Start; } } } clip.Notes.Add(noteToAdd); }
internal static void AddNoteOnOffEvent(double beatOffset, NoteEvent ev, byte note, byte volume) { if (!ValidTrack()) { return; } uint tickOffset = (uint)(beatOffset * ticksPerBeat); if (ev == NoteEvent.NoteOn || ev == NoteEvent.NoteOff) { TrackData.AddRange(TranslateTickTime(tickOffset)); TrackData.Add((byte)(((byte)ev << 4) | ((byte)Channel & 0xF))); TrackData.Add(note); TrackData.Add(volume); } else { // Error handling here, or other handling } }
private static void AddNoteCutting(Clip clip, NoteEvent noteToAdd) { var collidingNotes = clip.Notes.Where(x => noteToAdd.StartsInsideIntervalInclusive(x.Start, x.End)).ToArray(); if (collidingNotes.Length > 0) { foreach (var note in collidingNotes) { if (note.Start == noteToAdd.Start && noteToAdd.Duration > note.Duration) // largest note wins in the case of a collision { clip.Notes.RemoveAt(clip.Notes.IndexOf(note)); } else { // todo: maybe add extra logic to add back previous note if it spans the length of the note being added currently note.Duration = noteToAdd.Start - note.Start; } } } clip.Notes.Add(noteToAdd); }
private static void OnMidiRecieved(object sender, MidiEventReceivedEventArgs e) { if (e.Event != null) { if (e.Event.EventType == MidiEventType.NoteOn || e.Event.EventType == MidiEventType.NoteOff) { NoteEvent noteEvent = e.Event as NoteEvent; SendMidi(noteEvent); } else if (e.Event.EventType == MidiEventType.ControlChange) { ControlChangeEvent ccEvent = e.Event as ControlChangeEvent; SendMidi(ccEvent); } else if (e.Event.EventType == MidiEventType.ProgramChange) { ProgramChangeEvent pcEvent = e.Event as ProgramChangeEvent; SendMidi(pcEvent); } } }
private void Midi_MessageReceived(object sender, MidiInMessageEventArgs e) { NoteEvent noteEvent = e.MidiEvent as NoteEvent; if (noteEvent != null) { count++; Note note = new Note(noteEvent.NoteName, noteEvent.Velocity); AddMessageToEventLogBox($"{count} - {note.NoteType.ToStringDisplayable()}{note.Octave.ToString()} Vel:{note.Velocity}{Environment.NewLine}"); UpdateKeyboardImage(note); if (note.Velocity > 0) { this.chordFinder.Notes.TryAdd(note.GetNoteIdentifier(), note); } else { Note removedNote; this.chordFinder.Notes.TryRemove(note.GetNoteIdentifier(), out removedNote); } } }
//------------------------------------------------------------------------------------------------------- /// <summary> /// コンストラクタ /// </summary> /// <param name="tick"></param> /// <param name="root"></param> /// <param name="mode"></param> public Chord(string chordName, int tickFromStart, int mode) { //モードの登録 Mode = mode; //コードの開始時間を設定 TickFromStart = tickFromStart; //コードの根音の音高(root)と構成(structure)を取得 GetStructure(chordName, out byte root, out string structure); //rootとstructureからコードの構成音の配列(Elements)を作成 byte[] numbers = GetElementsConstitute(root, structure); if (numbers != null) { Elements = new NoteEvent[numbers.Length]; for (int i = 0; i < numbers.Length; i++) { Elements[i] = new NoteEvent(numbers[i], 80, 240 * 4) { Tick = tickFromStart }; } } //Base音の設定 Base = new NoteEvent((byte)(root - 24), 80, 240 * 4) //音高,音量,長さ { Tick = tickFromStart //Base音の開始タイミングを指定 }; //Chordの長さはBase音の長さとする Gate = Base.Gate; //伴奏音の設定 SetNotes(Mode); //PivotとPivotRangeを求める SetPivot(); }
private void midiEffectsIn(object sender, MidiInMessageEventArgs e) { //if (e.MidiEvent != null) // if (true) // Console.WriteLine("Inpute message from " + e.MidiEvent.Channel + " Comand" + e.MidiEvent.CommandCode); if (e.MidiEvent.Channel == 1 && e.MidiEvent.CommandCode != MidiCommandCode.AutoSensing) { if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOn) { NoteOnEvent noEvent = (NoteOnEvent)e.MidiEvent; if (noEvent.NoteNumber <= 107 && noEvent.NoteNumber >= 36) { int button = Launchpad.getButtonNo(noEvent.NoteNumber); int red = noEvent.Velocity & 0x3; int green = noEvent.Velocity & 0x30; green = green >> 4; if (red == 0 && green == 0) { buttons[button].LED = Color.FromArgb(170, 170, 170); } else { buttons[button].LED = Color.FromArgb(red * 85, green * 85, 0); } } } if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOff) { NoteEvent nEvent = (NoteEvent)e.MidiEvent; if (nEvent.NoteNumber <= 107 && nEvent.NoteNumber >= 36) { int button = Launchpad.getButtonNo(nEvent.NoteNumber); buttons[button].LED = Color.FromArgb(170, 170, 170); } } } }
public static ProcessResultArray <Clip> Apply(ScaleOptions options, params Clip[] clips) { if (options.By != null) { clips = clips.Prepend(options.By).ToArray(); } ClipUtilities.NormalizeClipLengths(clips); if (clips.Length < 2) { return(new ProcessResultArray <Clip>(clips)); } var masterClip = clips[0]; var slaveClips = clips.Skip(1).ToArray(); var processedClips = slaveClips.Select(c => new Clip(c.Length, c.IsLooping)).ToArray(); for (var i = 0; i < slaveClips.Length; i++) { var slaveClip = slaveClips[i]; foreach (var note in slaveClip.Notes) { var masterNotes = SortedList <NoteEvent> .Empty; if (options.PositionAware) { masterNotes = masterClip.Notes.Where(x => x.InsideIntervalInclusive(note.Start, note.End)).ToSortedList(); } if (masterNotes.Count == 0) { masterNotes = masterClip.Notes; } var constrainedNote = new NoteEvent(note); constrainedNote.Pitch = options.Strict ? ClipUtilities.FindNearestNotePitchInSet(note, masterNotes) : ClipUtilities.FindNearestNotePitchInSetMusical(note, masterNotes); processedClips[i].Notes.Add(constrainedNote); } } return(new ProcessResultArray <Clip>(processedClips)); }
private static void OnEventReceived(object sender, MidiEventReceivedEventArgs e) { var midiDevice = (MidiDevice)sender; NoteEvent ev = e.Event as NoteEvent; if (ev != null) { if (e.Event.EventType == MidiEventType.NoteOn && ev.Velocity > 0) { Console.WriteLine("Key " + ev.NoteNumber.ToString() + " pressed"); state.PressKey(ev.NoteNumber); //Process keybinding events when a key is pressed bindings.ProcessState(state, cursor); } else if (ev.Velocity == 0) { Console.WriteLine("Key " + ev.NoteNumber.ToString() + " released"); state.ReleaseKey(ev.NoteNumber); } } }
private void FindNoteOn(NoteEvent offEvent, List <NoteOnEvent> outstandingNoteOns) { bool found = false; foreach (NoteOnEvent noteOnEvent in outstandingNoteOns) { if ((noteOnEvent.Channel == offEvent.Channel) && (noteOnEvent.NoteNumber == offEvent.NoteNumber)) { noteOnEvent.OffEvent = offEvent; outstandingNoteOns.Remove(noteOnEvent); found = true; break; } } if (!found) { if (strictChecking) { throw new FormatException(String.Format("Got an off without an on {0}", offEvent)); } } }
private static void MaskNotesByClip(Clip clipToMask, Clip maskClip) { // var smallestGap = 1 / 256m; var maskClipIx = 0; while (maskClipIx < maskClip.Notes.Count) { var maskNote = maskClip.Notes[maskClipIx]; int i = 0; while (i < clipToMask.Notes.Count) { var note = clipToMask.Notes[i]; var clonedNote = new NoteEvent(note); if (maskNote.CrossesStartOfIntervalInclusive(clonedNote.Start, clonedNote.End)) { note.Duration = maskNote.End - note.Start; note.Start = maskNote.End; } else if (maskNote.CrossesEndOfIntervalInclusive(clonedNote.Start, clonedNote.End)) { note.Duration -= note.End - maskNote.Start; } else if (maskNote.InsideIntervalInclusive(clonedNote.Start, clonedNote.End)) { note.Duration = maskNote.Start - note.Start; note.Pitch = maskNote.Pitch; if (clonedNote.End > maskNote.End) { clipToMask.Notes.Add(new NoteEvent(note.Pitch, maskNote.End, clonedNote.End - maskNote.End, note.Velocity)); } } i++; } maskClipIx++; } }
public static void EnlargeClipByLooping(Clip clip, decimal newLength) { if (newLength < clip.Length) { return; } var loopLength = clip.Length; var currentLength = loopLength; var notesToAdd = new List <NoteEvent>(); while (currentLength < newLength) { foreach (var note in clip.Notes) { if (note.Start + currentLength < newLength) { var noteToAdd = new NoteEvent(note) { Start = note.Start + currentLength }; if (note.End + currentLength > newLength) { noteToAdd.Duration = newLength - noteToAdd.Start; // don't exit here as there might be more stacked/clustered notes that also fit } notesToAdd.Add(noteToAdd); } else { break; } } currentLength += loopLength; } clip.Length = newLength; clip.Notes.AddRange(notesToAdd); }
protected bool Equals(NoteEvent other) { return base.Equals(other) && Length == other.Length && Key == other.Key && DynamicValue == other.DynamicValue; }
void ExecuteNoteEvent(NoteEvent be) { //invisible notes & landmine notes if (be.noteEventType == NoteEventType.mine || be.noteEventType == NoteEventType.invisible) return; //none sound object if (soundObjects[be.id] == null) { /* if (bms.info.soundHeaders.Count <= (int)be.id || bms.info.soundHeaders[(int)be.id] == null) Debug.Log("Audio File id(" + be.id + ") missing"); else Debug.Log("Audio File '" + bms.info.soundHeaders[(int)be.id].name + "' missing"); */ StartCoroutine("AddCombo", be.l); } else { AudioSource audioSource = soundObjects[be.id].GetComponent<AudioSource>(); AudioMixerGroup targetMixer = backMixer; if (audioSource.clip.loadState == AudioDataLoadState.Loaded) { if (be.x != 0) { targetMixer = keyMixer; } audioSource.outputAudioMixerGroup = targetMixer; audioSource.Play(); } else Debug.Log("AudioSource" + audioSource.clip.name + "Play Failed"); } if (be.x != 0) StartCoroutine(AddCombo(be.l)); /*} catch { if(bms.info.soundHeaders.Count <= (int)be.id || bms.info.soundHeaders[(int)be.id] == null) Debug.Log("Audio File id(" + be.id + ") missing"); else Debug.Log("Audio File '" + bms.info.soundHeaders[(int)be.id].name + "' missing"); }*/ }