Startup/Resource utilities

Several scripts I’ve kept in Platform.userAppSupportDir, I’ve decided to share with everyone.

In order:

  • terminate all SC related processes from the OS
  • display *all* server options (or save as specific server configuration)
  • quarks utility script
startup.scd
ShutDown add: // thisProcess.shutdown

{
	defer

	{ #
		[
			scsynth
			,
			supernova
			,
			sclang
			,
			scide
		]

		.do

		{
			|x|

			thisProcess.platform.killAll

			(
				format

				(
					"%.%" , x ,

					(
						Platform.case

						{
							\windows
						}{
							"exe"
						}{
							\osx
						}{
							"app"
						}{
							\linux
						}{
							// "?"
						}

					)

				)

			)

		}

	}

}
server_options.scd
ServerOptions.instVarNames.asSortedList.collect
{
	|option|

	option ->
	(
		ServerOptions( ) perform: option
	)
}
.collect
{
	|option|

	format
	(
		".%\n(\n\t%\n)\n"
		,
		option.key.asSetter
		,
		(
			/**
			if(
				(
					option.value.isKindOf(Number)
				)
				&&
				{
					option.value > 2.squared
				}
			){
				"2 **" + option.value.nextPowerOfTwo.factors.size
			}{**/
				
			if(
				option.key.asString.contains("Device")
			){
				"ServerOptions.%s[0]" format: option.key
			}{
				option.value.cs
			}
			
			/**
			}**/	
		)	
	)
}
.addFirst
(
	"ServerOptions\n(\n\n)\n"
)
.join
quarks.scd
thisProcess.recompile // ctrl + home

(

if

(
	not

	(
		Git.checkForGit
	)
)

{
	openOS

	(
		"https://www.google.com/search?q=download+git"
	)
}

{
	Quarks.checkForUpdates

	(
		quarkAction:

		{
			|q|

			printAll

			(
				q.data.order.collect

				{
					|x|

					format

					(
						"%:%%", x, $\t, perform ( q.data , x )
					)
				}

				.addFirst

				(
					format

					(
						"%%%%%", * insert

						(
							$\n ! 4, 2, q.name
						)
					)
				)
			)
		},

		done:

		{
			if

			(
				Quarks.installed.size > 0
			)

			{
				{
					Quarks.gui

					;

					1.wait

					;

					Window.allWindows.last.view.alwaysOnTop_(true).onClose_

					{
						Document.current.selectLine(148)

						;

						thisProcess.recompile
					}
				}

				fork:

				(
					AppClock
				)
			}

			{
				load

				(
					Platform.userAppSupportDir ++ "/quarks_urls.scd"
				)

				??

				{
					Quarks.install("https://github.com/supercollider-quarks/Bjorklund")
				}
			}
		}
	)
}

)

(
	[
		Platform.userAppSupportDir +/+ "quarks_urls.scd"

		,
	
		LanguageConfig.currentPath
	]

	do: open

	(
		Document , _
	)
)

(
	Quarks.installed.collect(_.name).sort.printAll.size
)

(

File.use

(
	Platform.userAppSupportDir ++ "/quarks_urls.scd"

	,

	"w+"

	,

	write

	(
		_ , Quarks.installed.collect{ |q| q.name -> q}.asDict.order.collect{ |q| "\n\t" ++ Quark(q).url.cs ++ "\n\t," }.join.drop(-3).addFirst("\n]\n[").rotate(-3).addAll("\ndo: install\n\n(\n\tQuarks , _\n)")
	)
)

)

(
	LanguageConfig.includePaths.collect(_.basename).sort.printAll.size
)

(
	this.l_

	(
		LanguageConfig.includePaths
	)

	;

	l.do{ |x| LanguageConfig.removeIncludePath(x) }

	;

	LanguageConfig.store(LanguageConfig.currentPath)

	;

	this.l_

	(
		l.collect{ |x| x.basename -> x }.asDict
	)

	;

	l.order.do{ |x| LanguageConfig.addIncludePath(l[x.postln]) }

	;

	LanguageConfig.store(LanguageConfig.currentPath)
)

(

this.q_

(
	// "AlgaLib"
)

)

(
	Quarks.uninstall(q).installed.collect(_.name).reverse.printAll.includesEqual(q)
)

(

{
	Quarks.clear

	;

	File.deleteAll(Platform.userAppSupportDir +/+ "downloaded-quarks")

	;

	openOS(Platform.userAppSupportDir +/+ "downloaded-quarks")

	;

	openDocument(Platform.userAppSupportDir +/+ "sclang_conf.yaml") // set includePaths: []
}

fork:

(
	AppClock
)

)

thisProcess.recompile // ctrl + end

quarks.scd requires region by region excecution since most operations require thisProcess.recompile… thus breaking the continuity of evaluated code.

1 Like

If there’s anyone with something useful… it could be shared here.

The following script evaluates asynchronous functions synchronously on the server… so one could, for instance:

~sync.({ SynthDef(\, { }).add }, { Synth(\) })

It may prove useful… it’s extremely simple:

~sync = 

{
	|...sync|
	
	s.bind
	
	(
		FunctionList
		
		(
			sync.collect
			
			(
				(
					_
				)
			
				<>
				
				{
					s.sync
				}
			)
		)
	)
}