This forum is in permanent archive mode. Our new active community can be found here.

Simple Python Guitar Script (SPGS?!)

edited October 2007 in Technology
After school had finished yesterday I gave guitar lessons like every day. Then this on student asked me: "Wouldn't it be awesome to have a program ask you what chord you want and then just spit it out ?!" I told him that there are lots of flash programs out there that do that and that it would be much easier to just look at a chord table. That night it was raining and I had nothing to do. Totally bored I read through a few tutorials on how to program python online, since it could be useful someday. This all happend on Friday.

Now I present you with the ULTIMATE python script (SPGS?!). To tell the truth it is more than simple and stupid, but maybe someone sees a use for it. Here is the code:


print
print "~Chord directory~"
print " Press Ctrl+D to quit"

C = "032010"
Cm = "x35543"
D = "000232"
Dm = "xx0231"
D7 = "xx0212"
F = "003211, 133211"
Fm = "133111"
G = "320003, 355433"
Gm = "355333"
B = "024442"
Bm = "113321"
E = "022100"
Em = "022000"
A = "003330"
Am = "x02210"


while True:

print
x = input("Which chord are you looking for? ")

print x


P.S. I always wanted to paste code somewhere. ;)

Comments

  • You should use a dictionary. I will show you how it is done, later.
  • You probably could have spent that time memorizing them ~_^
  • I read about the dictionary thing, but I had already typed it all up. I would still be very happy if you could show me how it is done right. ;)
  • You are all unknowing on the subject of memorizing chords.

    YOU DONT MEMORIZE THEM!

    You learn what scales they are derived from and build them, simple as that, even more you don't even have to learn the scales you can just learn the root and the steps to the kind of scale you want and viola!

    Major scales: whole-step, whole-step, half-step, whole-step, whole-step, whole-step, half-step.
    Minor scales: whole-step, half-step, whole-step, whole-step, half-step, whole-step, whole-step.

    You build chords by combining three or more notes at the same time, usually a simple chord is the first third and fifth notes on a scale.

    I don't feel like explaining anymore since it's so simple.

    Learn music theory people!
  • edited October 2007
    I agree, it's all about scales. I wasted $83 and got a 5 on my Music Theory AP test and was in all the bands there were at my high school, so I know what I'm talking about.

    Also, your program doesn't take into consideration every chord there is. There are more than just major and minor chords, and there are also different inversions of those chords.

    If you need to find a chords, look it up on the internet, buy a book, or learn to build them from scales like I did. If you want to learn your chords, I think the way to do it is the way I forced myself to. I decided played guitar in my high school jazz band my senior year, and it forced me to learn a lot more than I would have ever learned on my own. I also had to take into consideration inversions, where on the guitar the chord was, what octave it sounded better in, did I want to repeat notes in the chord, and a lot more. A music theory class was helpful too, but not as much. Playing jazz really humbled me as a guitar player and was a great learning experience.
    Post edited by Kazuo on
  • There are hundreds of chords, memorizing them is useless.

    I been playing music since I can remember, and I have a minor on music theory.

    I have played for orchestras, bands, symphonies I dedicate my life to music.

    A chord book is pretty much a lazy man's excuse to learn chords.

    Jazz is fun to play, i remember being in my school's jazz band for four consecutive years (from 7th to 10th grade.)

    Yes I never went to a public school, bite me.
  • Yes I never went to a public school, bite me.*CHOMP*
  • *gets e-chomped*

    Have you notice that this forum gets off topic really easily?
  • *gets e-chomped*

    Have you notice that this forum gets off topic really easily?
    Isn't that why we're here?
  • edited October 2007
    There are many problems with your program that I did not fix. For example, it could use a proper quitting function. Also, the program will fail if the user gives bad input. However, I did fix one problem by replacing input with raw_input. raw_input reads stdin and returns a string. input reads stdin and evaluates what the user types as python code. You definitely don't want the user inputting code to be evaluated. You just want them typing in a string. In all other ways, I wrote this program to be functionally identical to yours. I just wrote it in a better way.

    #!/usr/bin/python
    START = "\n~Chord directory~\nPress Ctrl+D to quit\n"
    PROMPT = "Which cord are you looking for? "

    chord = { 'C':'032010', 'Cm':'x35543', 'D':'000232', 'Dm':'xx0231', 'D7':'xx0212', 'F':'003211, 133211', 'Fm':'133111', 'G':'320003, 355433', 'Gm':'355333', 'B':'024442', 'Bm':'113321', 'E':'022100', 'Em':'022000', "A":'003330', 'Am':'x02210' }

    print START
    while True:
    print chord[raw_input(PROMPT)]
    Post edited by Apreche on
  • edited October 2007
    Thanks!

    BTW, I had 7 years of guitar lessons and with that music theory. I do a agree with The wired. I was just bored and looking for goal which I would be able to accomplish with python. Don't take it to serious. ;)
    Post edited by kiwi_bird on
  • Ok, sorry, just that there's so many people who don't understand those simple little things that make a huge difference.
  • edited October 2007
    I teach most of my students a few chords first because they give them instant gratification. That way they can play their one favorite song, brag to their friends and not stop learning guitar because it seams hopeless. I've tried to teach a few of my pupils how chords are built up first, but it is hopeless.

    Edit: If you (The wired.) have time you could maybe right something about how chords work. I haven't been able to teach my pupils without them starting to cry. ;)
    Post edited by kiwi_bird on
  • Sure just give me a few minutes.
  • Cool, thanks and +1!
  • Part 1: getting started.
    The first thing one should know about building chords is the difference between whole-tones and semi-tones, a semi-tone is the distance from on fret to the next such as from B to C or from A to A#. Whole-tones are a two fret distance on a guitar, such as from A to B.

    Part 2: Scale formulas.
    Scales follow a simple formula which anyone can memorize, as an example I'll use a key of C, just because there's only natural notes.

    C D E F G A B C
    | | | | | | | |
    1 2 3 4 5 6 7 1
    R
    O
    O
    T

    There's a pattern there which will be repeated on every single major scale.

    Whole-tone, whole-tone, semi-tone, whole-tone, whole-tone, whole-tone, semi-tone.
    That's it, that's that pattern that's followed on a major scale, it's pretty much the backbone of music to make an analogy.

    Start on any key, C,B,D#, you name it! and if you follow the pattern than you will see you just made a major scale!

    The pattern for the minor scales is as follows: whole-tone, semi-tone, whole-tone, whole-tone, semi-tone, whole-tone, whole-tone.

    Part3:chords
    Many people ask "what does scales have to do with chords?" the answer is: everything.

    Chords are basically segments of scales!

    Get any scales, let's use C again, and play the first, third and fifth notes in it. You will probably notice that makes a chord!






    Tell me how this part is so I can continue....
  • Great! You could post the whole thing here then.

    Do you mind if I translate it to German?
  • Do whatever you want with it, it's yours :)

    I will post the other part in the new thread.
  • Superb! (I can't think of any other adjective that describes my feelings and that I haven't used here yet.)
Sign In or Register to comment.