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
Chord generator class
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
GrandJu



Joined: Jul 04, 2010
Posts: 32
Location: Rennes France

PostPosted: Mon Apr 25, 2011 4:16 am    Post subject: Chord generator class Reply with quote  Mark this post and the followings unread

Hi,

Here is a class I coded to generate chord. I am not a solfege specialist, I get chords description in wikipedia, so if important chords are missing or if there are some errors, please advise me.

Use this public class in another chuck file or simply uncomment example at the end of the file.

Have fun
Ju


Code:


public class chord{

6./5.=>float minor_third;
5./4.=>float major_third ;

3./2.=>float perfc_fifth ;
64./45.=>float dimin_fifth ;
8./5.=>float augmt_fifth;

5./3.=>float dimin_sevth ;
9./5.=>float minor_sevth;
15./8.=>float major_sevth;

//float perfc_elevn ;
//float major_thirt;

Gain input;
input => Gain third_u;
input => Gain fifth_u;
input => Gain seveth_u;
1=> input.gain;
0=> third_u.gain;
0=> fifth_u.gain;
0=> seveth_u.gain;


fun UGen fondamental (UGen @ in){
   in => input;
return input;   
}

fun UGen third (){
   return third_u;   
}

fun UGen fifth (){
   return fifth_u;   
}

fun UGen seventh(){
   return seveth_u;   
}

fun void set_chord(int num){

   if (num == 0){
      // reset chord
      0=> third_u.gain;
      0=> fifth_u.gain;
      0=> seveth_u.gain;
   }
   else if (num == 1){
   //Major triad
      major_third=> third_u.gain;
      perfc_fifth=> fifth_u.gain;
      0=> seveth_u.gain;
   }
   else if (num == 2){
   //Minor triad
      minor_third=> third_u.gain;
      perfc_fifth=> fifth_u.gain;
      0=> seveth_u.gain;
   }

   else if (num == 3){
   //Augmented triad
      major_third=> third_u.gain;
      augmt_fifth=> fifth_u.gain;
      0=> seveth_u.gain;
   }

   else if (num == 4){
   //Diminished triad
      minor_third=> third_u.gain;
      dimin_fifth=> fifth_u.gain;
      0=> seveth_u.gain;
   }

   else if (num == 5){
   //Diminished seventh
      minor_third=> third_u.gain;
      dimin_fifth=> fifth_u.gain;
      dimin_sevth=> seveth_u.gain;
   }

   else if (num == 6){
   //Half-diminished seventh
      minor_third=> third_u.gain;
      dimin_fifth=> fifth_u.gain;
      minor_sevth=> seveth_u.gain;
   }

   else if (num == 7){
   //Minor seventh
      minor_third=> third_u.gain;
      perfc_fifth=> fifth_u.gain;
      minor_sevth=> seveth_u.gain;
   }

   else if (num == 8){
   //Minor major seventh
      minor_third=> third_u.gain;
      perfc_fifth=> fifth_u.gain;
      major_sevth=> seveth_u.gain;
   }

   else if (num == 9){
   //Dominant seventh
      major_third=> third_u.gain;
      perfc_fifth=> fifth_u.gain;
      minor_sevth=> seveth_u.gain;
   }

   else if (num == 10){
   //Major seventh
      major_third=> third_u.gain;
      perfc_fifth=> fifth_u.gain;
      major_sevth=> seveth_u.gain;
   }

   else if (num == 11){
   //Augmented seventh
      major_third=> third_u.gain;
      augmt_fifth=> fifth_u.gain;
      minor_sevth=> seveth_u.gain;
   }

   else if (num == 12){
   //Augmented major seventh
      major_third=> third_u.gain;
      augmt_fifth=> fifth_u.gain;
      major_sevth=> seveth_u.gain;
   }
   else {
      <<< "Invalid chord number">>>;
   }
   }
}

/* Chords number
0  reset chord

1 Major triad
2 Minor triad
3 Augmented triad
4 Diminished triad

5  Diminished seventh
6  Half-diminished seventh
7  Minor seventh
8  Minor major seventh
9  Dominant seventh
10 Major seventh
11 Augmented seventh
12 Augmented major seventh
*/

//Step input;
//Std.mtof(64) => input.next;

//chord chord_1;

//input => chord_1.fondamental => TriOsc s0 => ADSR ad => LPF filt =>NRev rev => dac;
//    chord_1.third() => TriOsc s1 => ad;
//    chord_1.fifth() => TriOsc s2 => ad;
//    chord_1.seventh() => TriOsc s3 => ad;

//chord_1.set_chord(8);

//rev.mix(.05);
//Std.mtof(89) => filt.freq;
//ad.gain (0.1);
//ad.set (1::ms,3::ms,0.8,50::ms);

//while (1){
//ad.keyOn();
//200::ms => now;
//ad.keyOff();
//400::ms => now;
//}





Back to top
View user's profile Send private message
frank discourse



Joined: Apr 26, 2010
Posts: 10
Location: sydney

PostPosted: Tue Jul 12, 2011 6:50 pm    Post subject: re chord gen
Subject description: impressed but still confused
Reply with quote  Mark this post and the followings unread

Hey GrandJu,

I uncommented the lower part of your chord gen as you advised
but am still a novice in progress as you know so I was not clear on how to enter the auto chord numbers to generate progression as i believe the script should do. Can you tell me how to do this?

I am at a stage with ChucK now where I really want to accelerate my skills but am feeling at a disadvantage to many of the people on the forums who are very familiar with similar coding environments.
Would you advise reading up on Java or Python to help with overall understandings to using the ChucK language? For example I need to understand the idea of 'public classes' and creating functions more.
What do you think would help?

My current strategy is scouring the web and examining other peoples code when I hit a problem I can't solve but solutions aren't always available to my level of understanding.

At the moment I am trying to get midi cc control into ChucK from a BCR2000.
It shows up in some of the example scripts correctly and sends encoder info but i'm having trouble translating this to parameter control.

if(msg.data1==176&&msg.data2==81)
{
msg.data3/100 => r.mix;
}

this is an example of how i'm trying to do this, i'm sure it is not a sensible way, where can I find info on this?

Thanks in advance for any directives Smile Frankie_d
Back to top
View user's profile Send private message
GrandJu



Joined: Jul 04, 2010
Posts: 32
Location: Rennes France

PostPosted: Mon Jul 18, 2011 1:06 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi Frankie_d,

This example is just playing one chord at a time. There is no progression.
If you want to do so, try to change the base note (Std.mtof(64) => input.next; ) or the chord type (chord_1.set_chord(8);) in the loop.

To improve your coding skills I advise you to read some course or tutorial on the web (C, C++, JAVA...). And of course read the Chuck_manual.pdf and examples provided with the program.

Concerning your midi control, I think it didn't work as you want because variable are computed as integer. You can use "cast" to force your computer to compute floating numbers:

Code:

if(msg.data1==176&&msg.data2==81)
{
(msg.data3 $ float) / 100. => r.mix;
<<<"r.mix",r.mix>>>
}


And don't hesitate to add print message ( <<< >>> ) to know what is realy computed in your script.

Have fun!
Ju
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 [3 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