BPM Correction

Genre-specific BPM ranges and correction logic.

This module provides genre-aware BPM validation and correction, helping detect half-time issues common in electronic music.

class mixref.detective.bpm_correction.Genre[source]

Bases: str, Enum

Supported music genres for BPM validation.

DNB = 'dnb'
TECHNO = 'techno'
HOUSE = 'house'
DUBSTEP = 'dubstep'
TRANCE = 'trance'
__new__(value)
class mixref.detective.bpm_correction.BPMRange[source]

Bases: object

BPM range definition for a genre.

min_bpm

Minimum typical BPM for the genre.

Type:

float

max_bpm

Maximum typical BPM for the genre.

Type:

float

typical

Most common BPM for the genre.

Type:

float

min_bpm: float
max_bpm: float
typical: float
__init__(min_bpm, max_bpm, typical)
class mixref.detective.bpm_correction.CorrectedBPM[source]

Bases: object

Result of BPM correction.

original_bpm

The original detected BPM.

Type:

float

corrected_bpm

The BPM after applying corrections.

Type:

float

was_corrected

Whether any correction was applied.

Type:

bool

correction_reason

Explanation of why correction was applied.

Type:

str | None

in_genre_range

Whether corrected BPM is within genre range.

Type:

bool | None

genre

The genre used for validation (if any).

Type:

mixref.detective.bpm_correction.Genre | None

original_bpm: float
corrected_bpm: float
was_corrected: bool
correction_reason: str | None = None
in_genre_range: bool | None = None
genre: Genre | None = None
__init__(original_bpm, corrected_bpm, was_corrected, correction_reason=None, in_genre_range=None, genre=None)
mixref.detective.bpm_correction.correct_bpm(bpm, genre=None, half_time_threshold=100.0)[source]

Apply genre-aware BPM corrections.

Common in electronic music production, BPM detection can sometimes detect “half-time” (half the actual tempo). This function corrects such issues and validates against genre expectations.

Parameters:
  • bpm (float) – The detected BPM value.

  • genre (Genre | None) – Optional genre for validation against expected ranges.

  • half_time_threshold (float) – BPM below which to consider doubling. Default: 100.0 (below this, likely detected half-time).

Returns:

CorrectedBPM with original BPM, corrected value, and validation info.

Return type:

CorrectedBPM

Example

>>> from mixref.detective.bpm_correction import correct_bpm, Genre
>>>
>>> # Half-time detection (87 BPM -> 174 BPM for DnB)
>>> result = correct_bpm(87.0, genre=Genre.DNB)
>>> print(result.corrected_bpm)
174.0
>>> print(result.was_corrected)
True
>>>
>>> # Already in range
>>> result = correct_bpm(174.0, genre=Genre.DNB)
>>> print(result.was_corrected)
False
mixref.detective.bpm_correction.is_in_genre_range(bpm, genre)[source]

Check if BPM is within typical range for a genre.

Parameters:
  • bpm (float) – The BPM value to check.

  • genre (Genre) – The genre to check against.

Returns:

True if BPM is within the genre’s typical range.

Return type:

bool

Example

>>> from mixref.detective.bpm_correction import is_in_genre_range, Genre
>>>
>>> is_in_genre_range(174.0, Genre.DNB)
True
>>> is_in_genre_range(120.0, Genre.DNB)
False
mixref.detective.bpm_correction.get_genre_range(genre)[source]

Get the BPM range for a specific genre.

Parameters:

genre (Genre) – The genre to query.

Returns:

BPMRange with min, max, and typical BPM values.

Return type:

BPMRange

Example

>>> from mixref.detective.bpm_correction import get_genre_range, Genre
>>>
>>> range_info = get_genre_range(Genre.TECHNO)
>>> print(f"{range_info.min_bpm}-{range_info.max_bpm} BPM")
120.0-140.0 BPM