Author |
Message |
huiyunng
Joined: Oct 12, 2012 Posts: 4 Location: malaysia
|
Posted: Fri Oct 12, 2012 1:41 am Post subject:
Chords in ChucK |
|
|
Hi, Would like to ask how should a chord be written so that it can be played if I want to use the global variable?
Example:
I would like to play C major Chord (C,E,G) using SinOsc and I would like to play in the 1st and 3rd beat.My global variable will be like that
[1,0,0,0,1,0,0,0] @=> int chord_ptrn_1[];
How to I write a chord that play it using the chord pattern?
Thanks |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Fri Oct 12, 2012 3:04 am Post subject:
|
|
|
That's for the programmer to decide. :) There are many ways you could implement it, and it depends on how the chords are to be played etc.
One way to do it is to use a matrix instead, with arrays of midi notes:
Code: | [[64, 70],[],[],[],[69, 72],[],[],[]] @=> int chord_ptrn_1[][]; |
_________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
huiyunng
Joined: Oct 12, 2012 Posts: 4 Location: malaysia
|
Posted: Fri Oct 12, 2012 3:48 am Post subject:
|
|
|
Hi, Thanks for the info. However I got some problem, I am not sure whether I am writing it right.
SinOsc s => dac;
.5 => s.gain;
[[64,70],[0],[0],[0],[73,51],[0],[0],[0]] @=> int chord_ptrn_1[][];
for (0 => int i; i =<chord_ptrn_1> s.freq;
1::second => now;
}
I got an error for the line 0 => i part saying that ...on types 'int' and 'int[][]"
Thanks |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Fri Oct 12, 2012 11:54 am Post subject:
|
|
|
huiyunng wrote: | Hi, Thanks for the info. However I got some problem, I am not sure whether I am writing it right.
SinOsc s => dac;
.5 => s.gain;
[[64,70],[0],[0],[0],[73,51],[0],[0],[0]] @=> int chord_ptrn_1[][];
for (0 => int i; i =<chord_ptrn_1> s.freq;
1::second => now;
}
I got an error for the line 0 => i part saying that ...on types 'int' and 'int[][]"
Thanks |
huiyunng - when posting code like above, you need to click the "Disable HTML in this post" and "Disable Smilies in this post", otherwise the forum may mash up the code like happened here, especially if you have less than or greater than as in "i < a.length". Could you post this piece of code again with those two checked? Thanks. :) _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
|
Back to top
|
|
|
huiyunng
Joined: Oct 12, 2012 Posts: 4 Location: malaysia
|
Posted: Fri Oct 12, 2012 12:45 pm Post subject:
|
|
|
SinOsc s => dac;
.5 => s.gain;
[[64,70],[0],[0],[0],[73,51],[0],[0],[0]] @=> int chord_ptrn_1[][];
for (0 => int i; i =<chord_ptrn_1; i++;{
Std.mtof(chord_ptrn_1[i]) => s.freq;
1::second => now;
} Last edited by huiyunng on Fri Oct 12, 2012 1:09 pm; edited 2 times in total |
|
Back to top
|
|
|
huiyunng
Joined: Oct 12, 2012 Posts: 4 Location: malaysia
|
Posted: Fri Oct 12, 2012 1:03 pm Post subject:
|
|
|
Thanks |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Fri Oct 12, 2012 2:56 pm Post subject:
|
|
|
Ok thanks!
First, if you want to play a chord you need more than one SinOsc instances. Example:
SinOsc s1 => dac;
SinOsc s2 => dac;
Next, chord_ptrn_1 is an array of arrays (which may also be called a matrix), so each element in it will be an array:
<<< "Second note in the fifth position: " + chord_ptrn_1[4][1] >>>;
will print this for the earlier example:
Second note in the fifth position: 51
A loop over the note matrix that printed all the note values could look something like this:
=============================
[[64,70],[0],[0],[0],[73,51],[0],[0],[0]] @=> int chord_ptrn_1[][];
for (0 => int i; i < chord_ptrn_1.size(); i++) {
for (0 => int j; j < chord_ptrn_1[i].size(); j++) {
<<< "Position " + i + ", note " + j + " = " + chord_ptrn_1[i][j] >>>;
}
}
==============================
That piece of code will run by itself - try pasting it into a file and running it.
I leave the actual assignment of frequencies to notes as an exercise to the reader. :)
You might benefit from having a look at how a general purpose C-style programming language works, in parallell to having fun with ChucK. Unfortunately the ChucK docs don't dive very deeply into what everything means at the basic level. Have a look at this Java tutorial on the for loop for instance:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
The main thing to keep in mind (besides "class" and other stuff that you might want to check out later) is that variable assignment in Java has the variable on the left side (int i=1), where ChucK has it on the right side (1 => int i).
BTW, I recommend these early basic Java tutorials to anyone trying to learn the basics of programming in any modern procedural programming language, as they are as excellent today as they were when they first appeared in the mid 90s. _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
heuermh
Joined: Dec 15, 2006 Posts: 19 Location: minneapolis
|
Posted: Tue Oct 23, 2012 3:41 pm Post subject:
|
|
|
Here's an example of something similar using Object-y stuff
https://github.com/heuermh/lick/blob/master/examples/multivoiceChordsExample.ck
There are a lot of "debug" statements in there because this particular example core dumped on early 1.3.x builds.
I suppose the Loops stuff could be simplified in some sort of Pattern class but I haven't really thought that through yet. And of course all of LiCK could use more documentation. |
|
Back to top
|
|
|
|