Chapitre 2 - Leçon 5 Pratique

TP : Importer de l'audio dans la Session et l'Arrangement

Ce TP vous guide dans l'écriture d'une extension capable d'automatiser l'importation de samples et l'exportation de pistes (stems), en s'appuyant sur l'exemple officiel strip-silence pour le traitement offline.
typescript Code source complet : extension.ts
import * as ableton from "@ableton-extensions/sdk";

// Remplacez ce chemin par le chemin absolu d'un fichier audio sur votre disque !
const filePath = "/your/path/to/sample.wav";

export function activate(activation: ableton.ActivationContext) {
    const context = ableton.initialize(activation, "1.0.0");

    // 1. Enregistrement des actions dans le menu contextuel (Session)
    context.ui.registerContextMenuAction("ClipSlot", "Create unwarped clip", "clipslot.Unwarped");
    context.ui.registerContextMenuAction("ClipSlot", "Create warped clip", "clipslot.Warped");

    // 2. Enregistrement des actions dans le menu contextuel (Arrangement)
    context.ui.registerContextMenuAction("AudioTrack.ArrangementSelection", "Create unwarped clip", "ArrangementSelection.Unwarped");
    context.ui.registerContextMenuAction("AudioTrack.ArrangementSelection", "Create warped clip", "ArrangementSelection.Warped");

    // 3. Commande : Importation brute dans un ClipSlot (Session)
    context.commands.registerCommand("clipslot.Unwarped", async (arg: unknown) => {
        try {
            const clipSlot = context.getObjectFromHandle(arg as ableton.Handle, ableton.ClipSlot);
            const imported = await context.resources.importIntoProject(filePath);
            await clipSlot.createAudioClip({ 
                filePath: imported, 
                isWarped: false, 
                loopSettings: { looping: false, startMarker: 1, endMarker: 5, loopStart: 1, loopEnd: 5 } 
            });
        } catch (e) {
            console.error(e);
        }
    });

    // 4. Commande : Importation synchronisée (Warped) dans un ClipSlot (Session)
    context.commands.registerCommand("clipslot.Warped", async (arg: unknown) => {
        try {
            const clipSlot = context.getObjectFromHandle(arg as ableton.Handle, ableton.ClipSlot);
            const imported = await context.resources.importIntoProject(filePath);
            await clipSlot.createAudioClip({ 
                filePath: imported, 
                isWarped: true, 
                loopSettings: { looping: true, startMarker: 1, endMarker: 5, loopStart: 1, loopEnd: 5 } 
            });
        } catch (e) {
            console.error(e);
        }
    });

    // 5. Commande : Importation brute dans l'Arrangement
    context.commands.registerCommand("ArrangementSelection.Unwarped", async (arg: unknown) => {
        try {
            const selection = arg as ableton.ArrangementSelection;
            const track = context.getObjectFromHandle(selection.selected_lanes[0]!, ableton.AudioTrack);
            const imported = await context.resources.importIntoProject(filePath);
            await track.createAudioClip({ 
                filePath: imported, 
                startTime: selection.time_selection_start, 
                duration: selection.time_selection_end - selection.time_selection_start, 
                isWarped: false 
            });
        } catch (e) {
            console.error(e);
        }
    });

    // 6. Commande : Importation synchronisée (Warped) dans l'Arrangement
    context.commands.registerCommand("ArrangementSelection.Warped", async (arg: unknown) => {
        try {
            const selection = arg as ableton.ArrangementSelection;
            const track = context.getObjectFromHandle(selection.selected_lanes[0]!, ableton.AudioTrack);
            const imported = await context.resources.importIntoProject(filePath);
            await track.createAudioClip({ 
                filePath: imported, 
                startTime: selection.time_selection_start, 
                duration: selection.time_selection_end - selection.time_selection_start, 
                isWarped: true 
            });
        } catch (e) {
            console.error(e);
        }
    });
}

Contenu premium

Abonnez-vous ou achetez la formation pour accéder à l'intégralité du contenu.

Offre limitée -50% : 00j 00h 00m
Abonnement
  • Accès illimité à 1700 formations
34,90€ 17,45€ /mois
Recommandé
Achat unique
  • Accès illimité à la formation
39,00€ 19,50€ Ajouter au panier Acheter maintenant