A Quark or a Plug-in visualising SynthDef

Dear advanced and experienced users,

Could anyone recommend a Quark or a Plug-in visualising SynthDef similar to Max or pd?
I appreciate your help in advance!

Best regards,

1 Like

For those not knowing Max and pd, can you explain what you are trying to achieve ?

1 Like

like this:

?

3 Likes

This is worth looking into:

http://sccode.org/1-5fA


It’s one of the more recent post to sccode… only 1200 characters:

s.boot;

(
var bufferSize = s.sampleRate * 1; // Buffer size is fixed. s.sampleRate * seconds makes sense.

if( ~plotterIn == nil, { ~plotterIn = Bus.audio( s, 2 ) } ); // Declare a global channel for the plotter input, stereo

if( ~plotterBuffer != nil, { ~plotterBuffer.free } ); // Reset the buffer if existant
~plotterBuffer = Buffer.alloc( s, bufferSize, 2 ); // Create our buffer, stereo

SynthDef( \toBuffer, { // A simple routing synth
	| bufNum |
	var in = In.ar( ~plotterIn, 2 ); // Takes an input
	RecordBuf.ar( in, bufNum, loop: 0, doneAction: 2 ); // And outputs it in our buffer
} ).add;
)

( // Demo Synth
SynthDef( \demoSynth, {
	| out = 0, freq = 220 |

	var snd = SinOsc.ar( freq!2 );
	snd = snd * EnvGen.kr( Env.perc( 0.1, 0.9 ), doneAction: 2 );

	Out.ar( out, snd );
} ).add
)

(
Synth( \toBuffer, [ \bufNum, ~plotterBuffer ] ); // Trigger the buffer synth
Synth( \demoSynth, [ \out, ~plotterIn, \freq, 110 ] ); // Then our favorite synth
)

// You will need to wait the bufferSize length before plotting it !
~plotterBuffer.plot // Finally print the result

if( ~plotterBuffer != nil, { ~plotterBuffer.free } ); // Free the buffer if existant
1 Like

They are visual programming languages for music and multimedia. Please refer to the following websites:

In Max and pd, users make objects in a patcher window and connect them using wires or using objects [send] and object [receive].

What I want to achieve is visualising the structures of networked Ugens.
For example, the following code

Out.ar(0, SinOsc.ar)

could be visualised as follows:
Screenshot 2022-02-24 at 10.37.14 AM

Yes, thank you!
Installed Graphviz in a terminal window under macOS 12.2.1 as follows:

brew install graphviz

However, Apple Page is launched when evaluating the following code:

Dot.view("/tmp/sc3-dot.dot");

Graphviz is successfully installed, but I cannot find an application Graphviz.
How could I let SC open the sc3-dot.dot file with graphviz using an SC code?

Thanks in advace!

Hello,

Thank you very much for referring to this post!
I have never thought that someone may interpret my question as one about plotting the waveform of a synthDef.
Probably my question was somewhat ambiguous.
In future, I will describe more accurately what I need to know!

No need to apologize – your question was completely clear.

hjh

1 Like

not sure about the Graphviz program but brew will install the dot program which you can execute like this:

dot -Tpdf /tmp/sc3-dot.dot -o test.pdf; open test.pdf
RDot.view

would need to be updated along the lines of

(
~view = {|fn|
    "dot -Tpdf % -o %.pdf; open %.pdf &".format(fn, fn, fn).systemCmd
}
)
~view.("/tmp/sc3-dot.dot");
1 Like

You can also open .svg files directly in Sc.

I’ve added a very simple viewer, it’s fine for small graphs, but for larger graphs you’ll want something nicer. Browsers are one option.

Dot.viaSvg = true; // run dot to generate an .svg file and view that
Dot.svgViewer = “chromium”; // use an external viewer, if nil (the default) opens directly in sc

3 Likes

On my end (m1max MBP, macOS 12.2.1), unixCmd and systemCmd do not work, but runInTerminal work with the slightly modified code, which you provided for me, as follows:

(
~view = {|fn|
    "dot -Tpdf % -o test.pdf; open test.pdf".format(fn).runInTerminal
}
)
~view.("/tmp/sc3-dot.dot");

I’ve made some changes so that sc3-dot works here under MacOs (12.2.1).

Here I need to set the absolute path to dot, and use either the ‘svg’ or ‘pdf’ render mode.

Dot.dotCmd = “/opt/homebrew/bin/dot”;
Dot.renderMode = ‘pdf’; // run dot to generate an .pdf file and view that, also ‘svg’ works

If it’s not working there’s a Dot.verbose flag that prints out what it’s trying to do.

Here .pdf files open in Preview and .svg files open in Chrome.

Revised archive is at the address above.

Perhaps this helps?

1 Like

Thank you for your kind response!

I resolved it by installing Graphviz using port command as follows:
sudo port install graphviz

Now it works perfectly!

Hi, I have tried your quark again and it only seems to work on linux in svg mode.

It would be amazingly helpful to give students an intuitive concept if it worked, but there are too few students who use linux. I have met less than 5 Linux users out of about 300 around me in the last 10 years here.

I hope you have time to update it so that it works in at least one mode for all platforms…

I tested it step by step as follows:

1. Install Graphviz

  1. Windows 11
    Download the 64-bit installer from the following website:
    "https://graphviz.org/download/".openOS

  2. macOS:

    1. Install macPort from the following website:
      The MacPorts Project -- Download & Installation
    2. Run the following command in a terminal window:
      sudo port install graphviz

    I tried also with homebrew in a terminal window as follows:

    1. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    2. brew install graphviz
  3. linux:
    Run the following command in a terminal window:
    sudo apt install graphviz

2. Install sc3-dot then reboot sclang

Quarks.install("https://gitlab.com/rd--/sc3-dot")

3. Configure Dot

Dot.verbose = true
  1. Windows 11:
    Download the 64-bit installer on the following site:
    Dot.dotCmd = "C:/Program Files/Graphviz/bin/dot.exe"
  2. macOS:
    not required
  3. linux:
    not necessary

4. Try the default mode

Dot.defaultSettings

Code to try:

(
{
	var m = LFSaw.kr(0.4, 0) * 24 + (LFSaw.kr([8, 7.23], 0) * 3 + 80);
	CombN.ar(SinOsc.ar(m.midicps, 0) * 0.04, 0.2, 0.2, 4)
}.draw
)

What happens after evaluating the above block of code:

  1. On Windows:
    Nothing happens except that the post window returns the following:

    [ syncCmd, dotFileToPdfFileFor, C:/Program Files/Graphviz/bin/dot.exe -Tpdf ‘C:\Users\prko\AppData\Local\SuperCollider\2057916179.dot’ -o ‘C:\Users\prko\AppData\Local\SuperCollider\2057916179.pdf’ ]
    [ asyncCmd, viewPdfFileFor, chrome ‘C:\Users\prko\AppData\Local\SuperCollider\2057916179.pdf’ ]
    → a Function

    Executing syncCmd in a command prompt windows returns the following error:

    Error: dot: can’t open ‘C:\Users\prko\AppData\Local\SuperCollider\2057916179.dot’: Invalid argument

  2. On macOS:
    Apple application Page tries to open a dot file, but cannot open it. (a screenshot is attached)

    [ OutputProxy.controlIndex, 0 ]
    → a Function

    Screenshot 2023-09-25 at 23.51.30

  3. On linux:
    Dotty opens the image, but the image has only boxes and lines. (a screenshot is attached)

    [ asyncCmd, viewDotFile, dotty ‘/tmp/126038554.dot’ ]
    → a Function

5. svg mode

Dot.viaSvg = true

Evaluating the code above returns the following error on Windows 11, macOS 12.7, and Linux:

ERROR: Message ‘viaSvg_’ not understood.

The following code seems to work:

Dot.renderMode = \svg

Code to try:

(
{
	var m = LFSaw.kr(0.4, 0) * 24 + (LFSaw.kr([8, 7.23], 0) * 3 + 80);
	CombN.ar(SinOsc.ar(m.midicps, 0) * 0.04, 0.2, 0.2, 4)
}.draw
)

What happens after evaluating the above block of code:

  1. On Windows:
    Nothing happens except that the post window returns the following:

    [ syncCmd, dotFileToSvgFileFor, C:/Program Files/Graphviz/bin/dot.exe -Tsvg ‘C:\Users\prko\AppData\Local\SuperCollider\207360631.dot’ -o ‘C:\Users\prko\AppData\Local\SuperCollider\207360631.svg’ ]
    [ asyncCmd, viewSvgFileFor, chromium ‘C:\Users\prko\AppData\Local\SuperCollider\207360631.svg’ ]
    → a Function

    Executing syncCmd in a command prompt windows returns the following error:

Error: dot: can’t open ‘C:\Users\prko\AppData\Local\SuperCollider\207360631.dot’: Invalid argument

  1. on macOS:
    Apple application Page tries to open a dot file, but cannot open it. (refer to the screenshot attached above)

    [ OutputProxy.controlIndex, 0 ]
    → a Function

  2. Linux
    sclang opens the correct image (a screenshot is attached), and the post window returns the following message:

    [ syncCmd, dotFileToSvgFileFor, dot -Tsvg ‘/tmp/1912791860.dot’ -o ‘/tmp/1912791860.svg’ ]
    → a Function

    However, the following code should not be evaluated. If it is evaluated, nothing happens:
    Dot.svgViewer = "chromium"

6. pdf mode
Dot.renderMode = \pdf
It seems to work!

Code to try:

(
{
	var m = LFSaw.kr(0.4, 0) * 24 + (LFSaw.kr([8, 7.23], 0) * 3 + 80);
	CombN.ar(SinOsc.ar(m.midicps, 0) * 0.04, 0.2, 0.2, 4)
}.draw
)

What happens after evaluating the above block of code:

  1. on Windows:
    Nothing happens except that the post window returns the following:

    [ syncCmd, dotFileToPdfFileFor, C:/Program Files/Graphviz/bin/dot.exe -Tpdf ‘C:\Users\prko\AppData\Local\SuperCollider\932621075.dot’ -o ‘C:\Users\prko\AppData\Local\SuperCollider\932621075.pdf’ ]
    [ asyncCmd, viewPdfFileFor, chromium ‘C:\Users\prko\AppData\Local\SuperCollider\932621075.pdf’ ]
    → a Function

    Executing syncCmd in a command prompt windows returns the following error:

    Error: dot: can’t open ‘C:\Users\prko\AppData\Local\SuperCollider\932621075.dot’: Invalid argument

  2. on macOS:
    Apple application Page tries to open a dot file, but cannot open it. (refer to the screenshot attached above)

    [ OutputProxy.controlIndex, 0 ]
    → a Function

  3. Linux
    Nothing happens, and post window returns the following message:

    [ syncCmd, dotFileToPdfFileFor, dot -Tpdf ‘/tmp/856451342.dot’ -o ‘/tmp/856451342.pdf’ ]
    [ asyncCmd, viewPdfFileFor, mupdf ‘/tmp/856451342.pdf’ ]
    → a Function

It works here under Debian/Gnu and Apple, I’ve not tried under Microsoft but it should work, if unixCmd and systemCmd work there.

You seem to have it working in Linux (excellent!) & for Apple perhaps see:

If you’ve got Graphviz installed on macOS, you’re in good shape. It tends to play nice and can even pop up right inside editors like Emacs and VSCode with minimal fuss – just install the right packages for your editor. You got Linux already, I see )) Now, Windows, well, that’s where things get a bit mysterious. Honestly, it’s not the go-to choice in this community over here I think.

In viewDotFile:

var viewerDefault = (osx: "open", linux: "dot -Txlib", windows: "/usr/local/bin/dotty");

Windows: A POSIX executable location is unlikely to be successful.

OSX: open depends on filesystem associations. ‘.dot’ is also a MS Word document template, so macOS is probably trying to treat it as a Word doc (hence opening it in Pages).

hjh

1 Like

I have already done what you mentioned, and I have also installed graphviz via MacPorts and via homebrew, but it does not work as you describe. I hope you can find a way to help me if you read my last post carefully. I wrote details of what I did to get your help and to show that it does not work as you describe!

Could you tell me the default software associated with the .dot on MacOS?

Thanks! your screenshot helps me.

On macOS, the ‘.dot’ files are stored in one of the following path:

  • /private/tmp/ when installing ‘Graphviz’ via MacPorts? or on macOS 12.7?
  • Platform.userAppSupportDir +/+ "tmp" when installing ‘Graphviz’ via homebrew or on macOS 13.5.2?

I installed ‘Graphviz Prevew’ for VSCode, and there I can see the image.

I think @rdd was just having a playful jab at the Windows users with that, all in good humor of course)))