import torch


def unit_to_midi(unit, midi_min, midi_max = 90.0, clip = False):
    """Map the unit interval [0, 1] to MIDI notes."""
    unit = torch.clamp(unit, 0.0, 1.0) if clip else unit
    return midi_min + (midi_max - midi_min) * unit