开发者

Do I need a while loop inside if statement for this?

I'm needing to program something in Applescript which I've never used, but this is more of a general programming question for this specific issue.

The problem: I'm using Midipipe to receive midi input from two different devices.

I want to use the input of the first device to modulate the second device output. The thing is the first device will send one midi note, and then the second device will send an arbitrary number of notes that all need to be modulated. The apple script needs to be continually modulating those notes, but then as soon as the first device sends another note, it changes the modulation.

So I'm thinking I need something like this:

Device one will send from notes 1-16 on channel 1

Device two will send from notes 1-7 on channel 2

Device one = x
Device two = y

if x = 1
 while x = 1
  return y
 end w开发者_如何学JAVAhile
end if

if x = 2
 while x = 2
  y = y + 12 --moving y notes up one octave
 end while
end if

if x = 3
 while x = 3
  y = y + 24 --moving y notes up one octave
 end while
end if

etc

Things aren't working yet, and I'm not sure if it's a problem with my logic? I'm getting the error "expected else but found while". I tried to put in an else statement and got a different error...


You're missing the then after if x = 1 and the other ifs.

The while at the first if is unnecessary:

if x = 1 then
 while x = 1
  return y
 end while
end if

This is tha same as

if x = 1 then
 return y
end

because you will return y when the loop begins, and this stops the loop.

At the second and third whiles, you'll get an infinite loop. This is because your loop is monitoring the x variable, but you are changing only the y. So, x will be 3 forever, and the script will never get out of the loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜