Skip to main content

Overview

The Clip class is an abstract base class representing a clip in the Lumix DAW. Clips are regions of audio or MIDI data placed on tracks. They can be moved, resized, renamed, and duplicated.

Namespace

Lumix.Clips

Inheritance

public abstract class Clip

Properties

Identity Properties

Id
string
required
Unique identifier for the clip. Automatically generated using Guid.NewGuid().
public string Id { get; }
Name
string
required
The display name of the clip.
public string Name { get; protected set; }
Enabled
bool
required
Whether the clip is active. Disabled clips are not played during playback.
public bool Enabled { get; set; }
Default: true

Track and Visual Properties

Track
Track
required
The track that contains this clip.
public Track Track { get; protected set; }
ClipWidth
float
required
The width of the clip in pixels, calculated based on duration and zoom level.
public float ClipWidth { get; protected set; }
Color
Vector4
required
RGBA color of the clip for visual identification.
public Vector4 Color { get; set; }

Time Properties

StartTick
long
required
The arrangement starting time of the clip in ticks.
public long StartTick { get; protected set; }
EndTick
long
required
The arrangement ending time of the clip in ticks.
public long EndTick { get; protected set; }
DurationTicks
long
required
The duration of the clip in ticks.
public long DurationTicks { get; protected set; }
StartMusicalTime
MusicalTime
required
The arrangement starting time in musical notation (bars:beats:ticks).
public MusicalTime StartMusicalTime { get; protected set; }
EndMusicalTime
MusicalTime
required
The arrangement ending time in musical notation (bars:beats:ticks).
public MusicalTime EndMusicalTime { get; protected set; }
DurationMusicalTime
MusicalTime
required
The duration in musical notation (bars:beats:ticks).
public MusicalTime DurationMusicalTime { get; protected set; }
StartMarker
long
required
The portion trimmed from the start of the clip content, in ticks.
public long StartMarker { get; protected set; }
EndMarker
long
required
The portion trimmed from the end of the clip content, in ticks.
public long EndMarker { get; protected set; }

State Flags

WantsToMove
bool
required
Flag indicating the clip is being moved between tracks.
public bool WantsToMove { get; protected set; }
ClipIsHovered
bool
required
Whether the mouse cursor is hovering over the clip (including menu bar).
public bool ClipIsHovered { get; protected set; }
MenuBarIsHovered
bool
required
Whether the mouse cursor is hovering over the clip’s menu bar specifically.
public bool MenuBarIsHovered { get; protected set; }
HasPlayed
bool
required
Whether this clip has been triggered during the current playback session.
public bool HasPlayed { get; set; }
DeleteRequested
bool
required
Flag to mark the clip for deletion.
public bool DeleteRequested { get; set; }
DuplicateRequested
bool
required
Flag to request clip duplication.
public bool DuplicateRequested { get; set; }

Methods

Play (AudioFileReader)

Triggers playback of an audio clip through the track engine.
public void Play(AudioFileReader audioFile, float offset, float endOffset)
audioFile
AudioFileReader
required
The audio file to play.
offset
float
required
Starting offset in the audio file (in seconds).
endOffset
float
required
Ending offset in the audio file (in seconds).

Play (MidiFile)

Triggers playback of a MIDI clip through the track engine.
public void Play(MidiFile midiFile, float offset)
midiFile
MidiFile
required
The MIDI file to play.
offset
float
required
Starting offset in the MIDI file (in seconds).

SetStartTick

Sets the starting time of the clip on the timeline.
public void SetStartTick(long tick)
tick
long
required
The start time in ticks.

GetStartTimeInMusicalTime

Gets the clip’s start time in musical notation.
public MusicalTime GetStartTimeInMusicalTime()
Returns: MusicalTime - Start time as bars:beats:ticks

GetEndTimeInMusicalTime

Gets the clip’s end time in musical notation.
public MusicalTime GetEndTimeInMusicalTime()
Returns: MusicalTime - End time as bars:beats:ticks

GetDurationInMusicalTime

Gets the clip’s duration in musical notation.
public MusicalTime GetDurationInMusicalTime()
Returns: MusicalTime - Duration as bars:beats:ticks

GetDurationInSeconds

Gets the clip’s duration in seconds.
public double GetDurationInSeconds()
Returns: double - Duration in seconds

Render

Renders the clip in the arrangement view, handling user interactions.
public void Render()
This method handles:
  • Clip visualization
  • Dragging and dropping
  • Selection
  • Context menu
  • Rename functionality

Abstract Methods

These methods must be implemented by derived classes:

GetClipDuration

protected abstract long GetClipDuration()
Returns the total duration of the clip content in ticks.

GetClipWidth

protected abstract float GetClipWidth()
Calculates and returns the visual width in pixels.

RenderClipContent

protected abstract void RenderClipContent(float menuBarHeight, float clipHeight)
protected abstract void RenderClipContent(Vector2 pos, float width, float height)
Renders the clip’s visual content (waveform, MIDI notes, etc.).

OnClipDoubleClickLeft

protected abstract void OnClipDoubleClickLeft()
Handles double-click events on the clip.

Example Usage

// Creating an audio clip
var audioClipData = new AudioClipData("drums.wav");
var audioClip = new AudioClip(audioTrack, audioClipData, startTick: 0);
audioClip.Color = new Vector4(0.8f, 0.3f, 0.2f, 1.0f);
audioTrack.Clips.Add(audioClip);

// Creating a MIDI clip
var midiClip = new MidiClip(midiTrack, "melody.mid", startTick: 1920);
midiClip.Enabled = true;
midiTrack.Clips.Add(midiClip);

// Getting clip timing information
MusicalTime startTime = audioClip.GetStartTimeInMusicalTime();
MusicalTime duration = audioClip.GetDurationInMusicalTime();
double durationSeconds = audioClip.GetDurationInSeconds();

Console.WriteLine($"Clip starts at {startTime.Bars}:{startTime.Beats}:{startTime.Ticks}");
Console.WriteLine($"Duration: {duration.Bars} bars, {durationSeconds:F2} seconds");

// Moving a clip
audioClip.SetStartTick(3840); // Move to bar 3 (assuming 4/4 time, 480 PPQ)

Derived Classes

  • AudioClip: For audio files (WAV, MP3, etc.)
  • MidiClip: For MIDI data

See Also

Build docs developers (and LLMs) love