electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Chords in ChucK
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
huiyunng



Joined: Oct 12, 2012
Posts: 4
Location: malaysia

PostPosted: Fri Oct 12, 2012 1:41 am    Post subject: Chords in ChucK Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Oct 12, 2012 3:04 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
huiyunng



Joined: Oct 12, 2012
Posts: 4
Location: malaysia

PostPosted: Fri Oct 12, 2012 3:48 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Oct 12, 2012 11:54 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Oct 12, 2012 11:56 am    Post subject: Reply with quote  Mark this post and the followings unread

Also, welcome to electro-music.com huiyunng!
_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
huiyunng



Joined: Oct 12, 2012
Posts: 4
Location: malaysia

PostPosted: Fri Oct 12, 2012 12:45 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
huiyunng



Joined: Oct 12, 2012
Posts: 4
Location: malaysia

PostPosted: Fri Oct 12, 2012 1:03 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Oct 12, 2012 2:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
heuermh



Joined: Dec 15, 2006
Posts: 19
Location: minneapolis

PostPosted: Tue Oct 23, 2012 3:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use