Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Score examples and Platform.defaultTempDir on OSX #4221

Merged
merged 5 commits into from
Jan 17, 2019

Conversation

geoffroymontel
Copy link
Contributor

Purpose and Motivation

Fixes #1271

Types of changes

  • documentation of Score
  • changed Platform.defaultTempDir because /tmp is not writeable on OSX and is used in Score rendering

Checklist

  • All previous tests are passing
  • Tests were updated or created to address changes in this PR, and tests are passing
  • Updated documentation, if necessary
  • This PR is ready for review

Remaining Work

var dir;
dir = Platform.userAppSupportDir ++ "/tmp/";
dir.mkdir;
^dir;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change causes the defaultTempDir to no longer be /tmp on Linux. Maybe this is a good thing? It's worth discussing.

I'm guessing that Windows won't be too happy about ++ "/tmp/". You should make use of +/+. Also, we should keep using File.exists so that we don't call .mkdir every time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my comment about Windows. I didn't really understand how Platform works on Windows.

Copy link
Member

@gusano gusano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffroymontel It seems that /tmp not being writeable is a macOS-only issue (and from a basic search it seems to only happen on El Capitan although I'm not 100% sure about that).
I'd strongly suggest to not change default /tmp folder on linux but rather use that workaround for macOS only.

@geoffroymontel
Copy link
Contributor Author

@gusano @patrickdupuis thanks for your reviews ! I reverted Platform.defaultTempDir to /tmp on Linux and changed it in OSX only.


defaultTempDir {
var dir;
dir = Platform.userAppSupportDir +/+ "tmp";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffroymontel Now I believe that the trailing / is missing here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gusano I've tested the code and it seems to work without the trailing slash. Is it ok for you ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would the trailing slash be necessary? @gusano

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brianlheim it seems that Platform.defaultTempDir() already returns a trailing slash by default so it might be better to keep it that way to not break existing code?

@geoffroymontel I'm surprised that it works, I cannot test it now but my guess is that the file might end being
"/path-to-app-support-dir/tmpasScore-Help.aif"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @gusano you're right, I had not fully tested !
I added a trailing slash like on Linux

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, fair, did not know that. everyone should be using +/+ to concatenate paths though precisely to not get burned by this kind of detail. i believe other platform directory methods return paths without the trailing slash.

Copy link
Member

@gusano gusano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mossheim mossheim added comp: class library SC class library comp: help schelp documentation labels Jan 8, 2019
var dir;
// ensure trailing slash
dir = Platform.userAppSupportDir +/+ "tmp/";
if (File.exists(dir).not, { dir.mkdir; });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix formatting - if(File.exists(dir).not) { dir.mkdir };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I did not know this syntax was allowed !

if (bool) { "true".postln } { "false".postln }

I always thought parenthesis around functions were needed, because if was a function that would take a boolean and two functions.

if (bool, { "true".postln }, { "false".postln });

This syntax is not mentionned in http://doc.sccode.org/Reference/Control-Structures.html

Should I fill a separate PR for that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, why no space between if and the condition ?
is there a guide somewhere for the codebase formatting ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's this WIP guide. I seems to contradict what is being suggested here: https://github.com/supercollider/supercollider/wiki/Code-style-guidelines#whitespace-1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Patrick. I think I will rewrite it as :

if (File.exists(dir).not) { dir.mkdir };

then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the discussion on Slack, the style guide mentions a space after if for the C++ codebase, but no space for the SCLang codebase.

Then I will use

if(File.exists(dir).not) { dir.mkdir };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes done

// render the pattern to aiff (4 beats)

p.render("asScore-Help.aif", 4.0);
p.render(Platform.defaultTempDir ++ "asScore-Help.aif", 4.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use +/+ here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, I will do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

f.write(g.asCompileString);
f.close;
)

z = Score.newFromFile("score-test");
z = Score.newFromFile(Platform.defaultTempDir ++ "score-test");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use +/+ here and in the other spots above (i count 7)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and sorry this PR needs so much review for so little code

@alln4tural
Copy link

alln4tural commented Jan 16, 2019 via email

@geoffroymontel
Copy link
Contributor Author

@alln4tural my point was that I wrote initially

if (File.exists(dir).not, { dir.mkdir; });

and Brian suggested I wrote

if(File.exists(dir).not) { dir.mkdir };

instead, which is a style more in line with other programming languages, but I did not know SuperCollider allowed that.

@alln4tural
Copy link

alln4tural commented Jan 16, 2019 via email


defaultTempDir {
var dir;
// ensure trailing slash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last thing i didn't notice before -- this comment explains 'what', but not 'why' - can you please add a note that this is due to backwards compatibility, referencing this PR (#4221), so that future generations are not confused? sorry i didn't catch this before, after this it is definitely ready to merge. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !
I think it was the worst number of lines of code / number of requested changes ever 😆
I will try to do better next time !
Thanks everyone for your patience.

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, in the future don't need the entire URL, just the number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: class library SC class library comp: help schelp documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants