TR123e - EMCT Computing Final Project Version 1.0
Research Project Translation from gen~ to embedded Moog synth
Loading...
Searching...
No Matches
VelocityParser Class Reference

MIDI velocity threshold processor for note-on/note-off discrimination. More...

#include <VelocityParser.h>

Public Member Functions

 VelocityParser (int threshold=64)
 Construct velocity parser with configurable threshold.
bool isNoteOn (int velocity)
 Analyze velocity value and determine note-on status.

Private Attributes

int velocityThreshold
 Velocity threshold for note-on discrimination.

Detailed Description

MIDI velocity threshold processor for note-on/note-off discrimination.

The VelocityParser class provides intelligent MIDI velocity analysis with configurable threshold-based discrimination between note-on and note-off events. It handles MIDI protocol ambiguities and controller variations to ensure reliable note triggering behavior across diverse hardware and software configurations.

@design_principles

  • Simplicity: Single threshold comparison for predictable behavior
  • Configurability: User-adjustable threshold for different controllers
  • Reliability: Consistent discrimination across velocity ranges
  • Performance: Minimal computational overhead for real-time processing

@threshold_selection_guidelines Optimal threshold values depend on MIDI controller characteristics:

  • Conservative (32-48): Prevents false triggers, may reduce sensitivity
  • Balanced (49-80): Good compromise for most controllers and playing styles
  • Sensitive (81-100): Maximum expression, may allow false triggers
  • Aggressive (101-127): Only strong velocities trigger notes

@musical_applications

  • Monophonic synthesizers requiring reliable note triggering
  • Drum machines with velocity-sensitive sample triggering
  • Educational software with consistent note response
  • Live performance systems requiring predictable behavior
  • MIDI recording applications with clean note discrimination

@usage_example

VelocityParser parser(64); // Moderate threshold for balanced response
// In MIDI message processing:
if (messageType == kmmNoteOn) {
bool isNoteOn = parser.isNoteOn(velocity);
if (isNoteOn) {
synthesizer.noteOn(noteNumber, velocity);
} else {
synthesizer.noteOff(noteNumber);
}
}
VelocityParser(int threshold=64)
Construct velocity parser with configurable threshold.
Definition VelocityParser.cpp:22
bool isNoteOn(int velocity)
Analyze velocity value and determine note-on status.
Definition VelocityParser.cpp:42

Constructor & Destructor Documentation

◆ VelocityParser()

VelocityParser::VelocityParser ( int threshold = 64)

Construct velocity parser with configurable threshold.

Initialize velocity parser with threshold configuration.

Parameters
thresholdVelocity threshold for note-on discrimination Values above threshold trigger note-on events Values at or below threshold are interpreted as note-off Default: 64 (middle MIDI range, balanced sensitivity) Range: [1-126] practical limits for musical applications

@complexity O(1) - Constant time initialization @memory 4 bytes object size (single integer member) @thread_safety Safe for concurrent construction

@threshold_rationale Default value of 64 provides balanced behavior suitable for most musical applications and MIDI controllers. This represents 50% of the MIDI velocity range, offering good sensitivity while preventing false triggering from light touches or controller noise.

@boundary_considerations

  • Threshold = 0: All non-zero velocities trigger notes (maximum sensitivity)
  • Threshold = 127: No velocities trigger notes (effectively disabled)
  • Threshold = 126: Only maximum velocity triggers notes (minimum sensitivity)
Parameters
thresholdVelocity discrimination threshold

Simple initialization storing threshold value for subsequent velocity analysis. No validation performed for maximum real-time performance, relying on caller to provide musically appropriate threshold values.

Member Function Documentation

◆ isNoteOn()

bool VelocityParser::isNoteOn ( int velocity)

Analyze velocity value and determine note-on status.

Perform threshold-based velocity discrimination.

Performs threshold-based analysis of MIDI velocity values to determine whether the velocity represents a note-on or note-off event. Provides consistent discrimination behavior essential for reliable musical performance.

Parameters
velocityMIDI velocity value for analysis Range: [0-127] per MIDI specification Values outside range processed without validation
Returns
true if velocity indicates note-on event (velocity > threshold) false if velocity indicates note-off event (velocity ≤ threshold)

@complexity O(1) - Single integer comparison @determinism Identical output for identical inputs @realtime_safety Real-time safe (no allocation or blocking)

@discrimination_logic The method implements strict threshold comparison:

  • velocity > threshold → note-on event
  • velocity ≤ threshold → note-off event

This provides clean binary discrimination without hysteresis or complex state tracking, ensuring predictable behavior for musical applications requiring consistent note triggering.

@musical_implications Threshold-based discrimination affects musical expression:

  • Lower thresholds: Greater velocity sensitivity, potential false triggers
  • Higher thresholds: Reduced sensitivity, consistent triggering
  • Balanced thresholds: Optimal compromise for most musical contexts

@edge_case_behavior

  • velocity = 0: Always returns false (standard MIDI note-off)
  • velocity = threshold: Returns false (at-threshold interpreted as off)
  • velocity = threshold + 1: Returns true (above-threshold interpreted as on)

@controller_compatibility Different MIDI controllers exhibit varying velocity characteristics:

  • Weighted keyboards: Generally consistent velocity curves
  • Synth-action keys: May have different velocity response
  • Drum pads: Often require lower thresholds for sensitivity
  • Wind controllers: Continuous velocity, may need special handling
Parameters
velocityMIDI velocity value for analysis
Returns
Boolean note-on/note-off determination

@implementation_efficiency Single integer comparison provides optimal performance for real-time MIDI processing. No complex logic or state tracking required, ensuring deterministic execution time suitable for low-latency audio applications.

@precision_analysis Integer comparison eliminates floating-point precision concerns and provides exact threshold behavior. Binary discrimination ensures consistent results across processor architectures and compiler optimizations.

Member Data Documentation

◆ velocityThreshold

int VelocityParser::velocityThreshold
private

Velocity threshold for note-on discrimination.

Integer threshold value used for binary velocity discrimination. Values above this threshold are interpreted as note-on events, while values at or below are interpreted as note-off events.

@range [0-127] per MIDI velocity specification @default 64 (balanced sensitivity for most applications) @units MIDI velocity units (dimensionless integer)


The documentation for this class was generated from the following files: