Why doesn't Synth.new understand about scales? - supercollider

I can set a scale like this:
~pp = Scale.phrygian(\pythagorean);
I can then create a Pbind which plays the scale like this:
(
Pbind(
*[
instrument: \default,
scale: ~pp,
degree: Pseq([0, 1, 2, 3, 4, 5, 6, 7], inf),
amp: 0.5,
dur: 0.5
]
).play;
)
But Synth.new doesn't seem to get it at all (just results in silence):
b = Synth.new(\default, [\scale: ~pp, \degree: 3, \amp, 0.5]);
Interestingly, if I remove the scale parameter:
b = Synth.new(\default, [\degree: 3, \amp, 0.5]);
then I get a note, but it's always the same note. It doesn't respond to the degree parameter.
Ultimately, I would like to be able to trigger notes from an external OSC device (my phone!). This means hooking up OSCFunc to listen out for certain triggers, and play notes from a scale when those OSC events occur. I thought I could use Synth.new inside OSCFunc to actually play the notes, but it doesn't seem to know about scales, so I'm a bit stuck.
Can anyone provide any advice about how to acheive this?

Have a good read of the Pattern Guide, in particular Pattern Guide 07: Value Conversions. It's a good tutorial. It will tell you that these magical conversions are not used everywhere in SuperCollider, but only when you use Event-based scheduling such as Patterns (e.g. your Pbind). The value conversions are actually defined in "the default Event", as described further in that tutorial article.
One consequence of all of this is that, if you want to launch just one note but you still want value conversions, you can do it with the Event style of playing notes, which creates an event using () and then calls .play on it:
~synth = (instrument: \default, scale: [0,2,4,5,7,9,11], degree: 12.rand, amp: 0.5).play;
~synth = (instrument: \default, scale: [0,3,6,9], degree: 12.rand, amp: 0.5).play;
This still returns a Synth object.
See the Event helpfile for more on this way of doing it.

Related

Can't export my image from Google Earth Engine

I'm aware I'm far from the first person to ask this question, but I found myself likewise perplexed at how to export an image from this godforsaken program, and after trying to parse through a lot of JavaScript that might as well be Greek to me, I've decided I'm in need of an answer specific to my own plight. Below is my code:
var aer = ee.ImageCollection('USDA/NAIP/DOQQ')
.filter(ee.Filter.date('2020-02-01', '2020-09-04'));
var trueColor = aer.select(["R", 'G', 'B']);
var trueColorVis = {
min: 0.0,
max: 255.0,
};
var visual = trueColor.visualize({
bands: ['R', 'B', 'G'],
min: 0,
max: 255.0
})
Map.setCenter(-97.43, 42.03, 13)
Map.addLayer(trueColor, trueColorVis, 'True Color');
var TrueColorvis = trueColor.visualize({
bands: ['R', 'G', 'B'],
max: 0.4
});
// Create a task that you can launch from the Tasks tab.
Export.image.toDrive({
image: trueColorvis,
description: "Aerial view of Norfolk",
scale: 30
region: geometry
});
With 'geometry' being the desired area that I highlighted. I'm constantly faced with the error message:
Line 11: trueColor.visualize is not a function
And while I'm vaguely aware that this is because my image isn't a 'function,' I'm not sure how to make it one. I'm pressed for time on a final project for a class and really just need to move on to the next step, I really didn't expect this to be the part that sucked away multiple hours of my time.
I'm obviously pretty inexperienced with this program, so if an answer can be provided in a manner that doesn't rely on me having a solid depth of knowledge about this program, that would make a world of difference (exact reason I wasn't able to learn anything from answers to similar questions asked). Thanks!
The problem here is that trueColor is an ee.ImageCollection (many images), not ee.Image (one image). Only images have visualize().
To fix this, and do the same thing that Map.addLayer() does, use .mosaic() to combine the images:
var TrueColorvis = trueColor.mosaic().visualize({
...

Difference in behavior in OpenSCAD between % and #

Using OpenSCAD 2019.05 on Mac OS 10.15.7,
difference() {
cube(size = [14, 24, 17], center = false);
% cube(size = [10, 20, 17], center = false);
}
fails (sometimes with the familiar "No geometry" error, sometimes with a cube with no subtraction).
However, with only the substition of # for %, the expected behavior is produced. Am I misunderstanding the semantics of # and %?
(As you'd expect, I didn't write the code this way, I took CSG output from my original program and boiled it down to this example.)
I used to get confused by them too. % allows you to put things in the F5 preview of the model that will not show up in the actual render with F6. See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Modifier_Characters#Background_Modifier
"Ignore this subtree for the normal rendering process and draw it in transparent gray (all transformations are still applied to the nodes in this tree)."
So, the line with % is being ignored when you render it and it should result in the first cube being rendered unmodified.

Preserve cursor position after setValue in Ace editor

I'm developing a real time editor with ace and call editor.setValue() when ever there is a change in the editor and the cursor positions itself at random positions below the text. What I want is pretty obvious, the cursor to position exactly where the text ends after the set value loads the new texts. Any ideas??
that is not very simple at all, because if the text have changed the same position will not be the same anymore.
if you want to restore the same selection, you can use toJSON method
before = editor.selection.toJSON();
editor.setValue(editor.getValue() + "xxx")
editor.selection.fromJSON(before)
but that in addition to being wasteful for performance, will not work correctly in the case when lines are shifted e.g. editor.setValue("xxx\n" + editor.getValue())
In general it is a better to use session.insert/session.remove methods
editor.session.insert({row: 0, column: 0}, "xxx\n")
editor.session.remove({start: {row: 0, column: 1}, end: {row: 1, column: 1}})

function-like interpolation in React Native?

I have a scrollview with fixed length in my RN project that should act like a parralax scroll behavior. When I scroll and move the Y component, the X component of the header is moving right so when it is on top, it is 56 pixels away from the left edge, leaving enough place for the back arrow.
But it is linear. Is there a way to make it exponential. The best example would be the WhatsApp contact's parralax scroll:
Watch the Title "Dune"
How I have it now = red line (linear)
How I would like to = blue line (linear with easing, exponential, whatever it's called)
I got the scaling animation done, but the linear motion is like a thorn in my eye and the documentation for Animated values is overwhelming and unclear a bit.
I've defined:
scrollY: new Animated.Value(0)
in state and in my scrollview like this:
<ScrollView
onScroll={Animated.event(
[{nativeEvent: {contentOffset: {y: this.state.scrollY}}}]
)}
and my Animated.View inside of it looks like this:
<Animated.View
style={[
{marginTop: 30, alignSelf: 'flex-start' },
{translateX: headerTranslateX}
]}]}>
<Text>Title</Text>
</Animated.View>
Aand the interpolation:
const titleTranslateX = this.state.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE*0.6, HEADER_SCROLL_DISTANCE],
outputRange: [0, 0, 56],
extrapolate: 'clamp',
})
which is linear in nature (i tried setting 10+keypoints in inputRange and outputRange bit but it gets messy and doesn't look natural enough)
Any advice on how to achieve the desired effect?
The only thing it says in the Animated docs on easing (function interpolation) is:
Interpolation
Each property can be run through an interpolation first. An interpolation maps input ranges to output ranges, typically using a linear interpolation but also supports easing functions. By default, it will extrapolate the curve beyond the ranges given, but you can also have it clamp the output value.
It doesn't mention how you can add an easing function. However, in the source code you'll find this: https://github.com/facebook/react-native/blob/e2ce98b7c6f4f2fc7011c214f9edc1301ff30572/Libraries/Animated/src/Interpolation.js#L27
export type InterpolationConfigType = {
inputRange: Array<number>,
/* $FlowFixMe(>=0.38.0 site=react_native_fb,react_native_oss) - Flow error
* detected during the deployment of v0.38.0. To see the error, remove this
* comment and run flow
*/
outputRange: (Array<number> | Array<string>),
easing?: ((input: number) => number),
extrapolate?: ExtrapolateType,
extrapolateLeft?: ExtrapolateType,
extrapolateRight?: ExtrapolateType,
};
The easing function defaults to linear (t) => t, but you can make it any standard easing function. Here's a nice list: https://gist.github.com/gre/1650294
Note: this won't work if you're using useNativeDriver: true.
Hope this helps reduce the choppiness!

Change water color in d3 orthographic transition map

I am new to D3 and this is my first question to stackoverflow.
I am trying to change the color of the water in this example that contains transitions:
http://bl.ocks.org/mbostock/4183330
I am able to change the color in this example, which is static: http://bl.ocks.org/mbostock/3757125
I found this thread: How can I color ocean with topojson in d3 when I have coordinate info for land? However, this changes the area outside of the globe as well.
This section of the code appears to be the styling, but I can't figure what to add to change the water color.
c.fillStyle = "#bbb", c.beginPath(), path(land), c.fill();
c.fillStyle = "#f00", c.beginPath(), path(countries[i]), c.fill();
c.strokeStyle = "#fff", c.lineWidth = .5, c.beginPath(), path(borders), c.stroke();
c.strokeStyle = "#000", c.lineWidth = 2, c.beginPath(), path(globe), c.stroke();
Also, seeing the line of code below, I searched online for a reference list of possible topojson features and/or objects that might indicate water, and maybe I could figure out how to style that, but couldn't find one:
land = topojson.feature(world, world.objects.land),
I'm wondering if maybe this has something to do with canvas (which I don't really grasp).
Hopefully, I'm overlooking something obvious and noob-like.
Thanks much!
Ha! Of course:
Modify this line:
c.strokeStyle = "#ccc", c.lineWidth = .5 * ratio, c.beginPath(), path(globe), c.stroke();
To this:
c.fillStyle = "#000", c.beginPath(), path(globe), c.fill();
I feel silly, but I guess sometimes it takes writing it all out for the brain cells to click. Thanks!

Resources