Creating a new patch programatically

Zancudo's icon

Hi all,

I was wondering wether there is a way to create a new patch file from inside a 'master' patch.

The idea is that I am planning to create a sort of powerpoint patch to use for teaching. This means that I can have my slides with content but also have interactive bits in different slides. Most of the work is done and it works as I have the master patch loading different 'slide' patches into a [bpatcher]. This works well and I just need to clean up the code a bit before sharing.

My current issue is that I have to create each slide as a separate patcher with some default objects for communication. At the moment it means that I have to duplicate my 'slide' prototype outside of max and then change the filename before entering the contents. I would like to be able to automate this project from the master patch. Ideally I would like to have an 'add slide' button that creates the new file to a specific folder with a filename that is generated sequentially.

Any pointers?

Cheers

- Miguel

Roman Thilenius's icon

for like 8 pages: one bpatcher with 8 tabs

for hundreds of pages: maybe a bpatcher and then load different source files?

i also want to point you to the fact that you can make custom windows in max/msp, of arbitrary size, and also without any frame, using the window commands to [thispatcher.]

this way you can , for example, have a menubar "frame" (aka html?) on the top and a "subframe" for every page, where page 3 lets you open the patch for page 4.

p.s.:
if you are firm with poly~ you could store all pages there. but you can also have them all in the main "menubar" window or launch them direcly from disk using scrpting, shell commands, java or whatever)

Roman Thilenius's icon

not sure if i get you right with the filenames. but there are OS utils which let you rename a bunch of files to whatnot001, whatnot002, and creating such names programmatically in max is also a nobrainer.

Zancudo's icon

Hi Roman,

As you pointed out my main patch has a bpatcher and then just dynamically reloads it with different 'slide' source patches. Also, as you said I am using [thispatcher] to sort out the sizing (zoom levels), centering and other miscellaneous stuff. This is all done. I also use [thispatcher] to generate an abolute path to know where I am and then generate a list of available 'slide' files with some additional javascript to keep track of things.
This is all working fine so far.

My issue is that in order to add new pages to my presentation I have to:
1 manually create a new patch (apple+N)
2 Save it in my containing folder with a name that represents the order (e.g. slide_2)
3 Edit the contents.
4 Scan the folder for any existing max files so that they are available for me to select them/add them to my presentation.

This is all well and nice and it does currently work .

I guess that what I am hoping for is for one of those existing but undocumented ways to automate the above process. In my head it would mean some message to Max that simply creates a new file to a specific folder based on a template. As you mentioned, programatically keeping track and assigning names to the slide files is simple enough, I just don't know of a way of writing a new patch file to disk with a specific name from within another patch.

Whilst at the moment I am interested on doing this for teaching purposes, I can see different scenarios where this can be useful. The framework I have working so far was originally done for a user study where some sensor data was being captured and the participants would have some questions to answer at different points whilst recording sensor data at different times. This was done with that logic of just replacing the contents of a bpatcher to provide an interface for the different parts of the study. I can also imagine a case for pieces where my main patch could hold my sensor acquisition stuff and an output mixer section so that for any piece I have independent DSP patches that take my sensor input and runs it through different sound making algorithms that change across the duration of the piece (with some extra bits to crossfade between different sound processing patches)

In my question there is an implicit wish that someone else has come across a way to generate empty patcher files from a template that does not require me to go to the file menu, create a new file and type the name of it.

I know I could do this with the shell object and just make a new copy of my template and rename it. I am just hoping for a way that would work both for osx and windows so that it is not something that I just use myself but release it as a tool. Many of my colleagues are interested in using such a tool for teaching so the easier I can make it to work, the better.

Any pointers from cycling74 gurus?

- Miguel

ak's icon

You can write simple js script to copy and rename your template file. Or, since .maxpat is a plain text file, you could try putting its contents to a [text] object and write it to desired location. I haven't heard of a possibility of programmatically creating new patcher from template and then saving it under a given name.

Zancudo's icon

Hi AK,

Thanks for your input. Went with javascript in order to avoid using [shell].
I don't really know much js so I used one of the examples included that does copy files.

Thanks for the pointers

Cheers

- M