Skip to main content
Glama

multi-synth-execute

Execute multiple SuperCollider synth definitions simultaneously to create layered audio compositions or test sound combinations.

Instructions

複数のSynthDefを同時に実行します。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
synthsYes再生するシンセのリスト
durationNo再生時間(ミリ秒)。デフォルトは10000(10秒)

Implementation Reference

  • The main handler function for the 'multi-synth-execute' tool. It initializes the SuperCollider server, loads and plays multiple synths concurrently using Promise.all on loadAndPlaySynth, waits for the specified duration, cleans up the server, and returns a structured response with playback details or handles errors.
    async (
      { synths, duration = 10000 }:
        {
          synths: { name: string, code: string }[],
          duration?: number
        }
    ) => {
      try {
        const scServer = await initServer();
        const synthPromises = [];
    
        for (const synth of synths) {
          synthPromises.push(loadAndPlaySynth(scServer, synth.name, synth.code));
        }
    
        const loadedSynths = await Promise.all(synthPromises);
    
        console.error(`${synths.length}個のシンセを${duration / 1000}秒間演奏中...`);
        await new Promise(resolve => setTimeout(resolve, duration));
    
        await cleanupServer();
    
        console.error('複数シンセの演奏完了');
    
        return {
          content: [
            {
              type: "text",
              text: `${synths.length}個のシンセを同時に再生しました。`,
            },
            {
              type: "text",
              text: `再生したシンセ: ${synths.map(s => s.name).join(', ')}`,
            },
            {
              type: "text",
              text: `合計再生時間: ${duration / 1000}秒`,
            }
          ],
        };
      } catch (error) {
        console.error("複数シンセ実行エラー:", error);
        return {
          content: [
            {
              type: "text",
              text: `エラーが発生しました: ${error instanceof Error ? error.message : JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
            }
          ],
        };
      }
    }
  • Zod schema for the tool input parameters: an array of synth objects (each with name and code strings) and an optional duration in milliseconds (default 10000).
    {
      synths: z.array(
        z.object({
          name: z.string().describe("シンセの名前"),
          code: z.string().describe("シンセのコード")
        })
      ).describe("再生するシンセのリスト"),
      duration: z.number().optional().describe("再生時間(ミリ秒)。デフォルトは10000(10秒)")
    },
  • src/index.ts:143-207 (registration)
    Registration of the 'multi-synth-execute' tool on the MCP server, specifying the tool name, description, input schema, and handler function.
    server.tool(
      "multi-synth-execute",
      "複数のSynthDefを同時に実行します。",
      {
        synths: z.array(
          z.object({
            name: z.string().describe("シンセの名前"),
            code: z.string().describe("シンセのコード")
          })
        ).describe("再生するシンセのリスト"),
        duration: z.number().optional().describe("再生時間(ミリ秒)。デフォルトは10000(10秒)")
      },
      async (
        { synths, duration = 10000 }:
          {
            synths: { name: string, code: string }[],
            duration?: number
          }
      ) => {
        try {
          const scServer = await initServer();
          const synthPromises = [];
    
          for (const synth of synths) {
            synthPromises.push(loadAndPlaySynth(scServer, synth.name, synth.code));
          }
    
          const loadedSynths = await Promise.all(synthPromises);
    
          console.error(`${synths.length}個のシンセを${duration / 1000}秒間演奏中...`);
          await new Promise(resolve => setTimeout(resolve, duration));
    
          await cleanupServer();
    
          console.error('複数シンセの演奏完了');
    
          return {
            content: [
              {
                type: "text",
                text: `${synths.length}個のシンセを同時に再生しました。`,
              },
              {
                type: "text",
                text: `再生したシンセ: ${synths.map(s => s.name).join(', ')}`,
              },
              {
                type: "text",
                text: `合計再生時間: ${duration / 1000}秒`,
              }
            ],
          };
        } catch (error) {
          console.error("複数シンセ実行エラー:", error);
          return {
            content: [
              {
                type: "text",
                text: `エラーが発生しました: ${error instanceof Error ? error.message : JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
              }
            ],
          };
        }
      }
    );
  • Helper function used by the handler to load a SynthDef by name and code, create a synth instance from it, track it in activeSynths, and return the synth.
    async function loadAndPlaySynth(scServer: SCServer, synthName: string, synthCode: string): Promise<any> {
      const def = await scServer.synthDef(synthName, synthCode);
      const synth = await scServer.synth(def);
      activeSynths.push(synth);
      return synth;
    }
  • Helper function to initialize and boot the SuperCollider server lazily, ensuring only one instance, used by the handler.
    async function initServer(): Promise<SCServer> {
      if (serverInitPromise) {
        return serverInitPromise;
      }
    
      serverInitPromise = (async () => {
        try {
          console.error("SuperColliderサーバーを起動中...");
          const server = await (sc as any).server.boot({
            debug: false,
            echo: false,
            stderr: './supercollider-error.log'
          }) as SCServer;
    
          console.error("SuperColliderサーバー起動完了");
          scServerInstance = server;
          return server;
        } catch (err) {
          console.error("SuperColliderサーバー起動エラー:", err);
          serverInitPromise = null;
          throw err;
        }
      })();
    
      return serverInitPromise!;
    }
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Synohara/supercollider-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server