issue100:programmer_en_python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédenteDernière révisionLes deux révisions suivantes | ||
issue100:programmer_en_python [2015/08/30 15:18] – créée auntiee | issue100:programmer_en_python [2015/09/04 10:05] – [3] auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | First, let me say Happy 100 to Ronnie and the crew. It’s a privilege to be part of this milestone. | + | ====== 1 ====== |
+ | |||
+ | **First, let me say Happy 100 to Ronnie and the crew. It’s a privilege to be part of this milestone. | ||
This time I thought that I’d share some information on my new obsession. I’ve started repairing and building stringed musical instruments like guitars and violins. Believe it or not, there is a lot of math involved in musical instruments. Today, we will look at some of the math involved with the length of strings and where the frets should be placed on the fretboard. | This time I thought that I’d share some information on my new obsession. I’ve started repairing and building stringed musical instruments like guitars and violins. Believe it or not, there is a lot of math involved in musical instruments. Today, we will look at some of the math involved with the length of strings and where the frets should be placed on the fretboard. | ||
Ligne 5: | Ligne 7: | ||
Take a look at the picture of the guitar. I annotated various items in the image. The important things to look at are the Nut near the top of the fingerboard, | Take a look at the picture of the guitar. I annotated various items in the image. The important things to look at are the Nut near the top of the fingerboard, | ||
- | Now, the physics of vibrating strings tells us that if you half the vibrating string length of a theoretically perfect string, you will double the frequency of the vibrations. In the case of a guitar, this string length is between the nut and the saddle. This distance is referred to the Scale Length of the guitar. The half-point that allows for the doubled frequency is fret # 12. If correctly done, just by lightly placing your finger on the string at this location, you get a pleasing tone. There are a few other positions that this will happen, but the 12th fret should be the perfect location for this doubling, making the note go up one octave. | + | Now, the physics of vibrating strings tells us that if you half the vibrating string length of a theoretically perfect string, you will double the frequency of the vibrations. In the case of a guitar, this string length is between the nut and the saddle. This distance is referred to the Scale Length of the guitar. The half-point that allows for the doubled frequency is fret # 12. If correctly done, just by lightly placing your finger on the string at this location, you get a pleasing tone. There are a few other positions that this will happen, but the 12th fret should be the perfect location for this doubling, making the note go up one octave.** |
- | Different scale lengths will create different feel and tones. For example, guitars like the Fender Stratocasters® have a scale length of 25½”, which produces a rich and strong bell-like tone. On the other hand, Gibson guitars often use a scale length of 24¾”. This creates a lower string tension which makes an easier playing feel and a warmer tone. Other guitar manufacturers decided that a scale length of 25” makes a clearer tone than either of the other two “standard” scale lengths. | + | Tout d' |
+ | |||
+ | Cette fois-ci, j'ai pensé partager certaines informations sur ma nouvelle obsession. J'ai commencé à réparer et à construire des instruments de musique à cordes comme les guitares et les violons. Croyez-le ou non, il y a pas mal de maths dans les instruments de musique. Aujourd' | ||
+ | |||
+ | Jetez un œil à l' | ||
+ | |||
+ | En effet, la physique des cordes vibrantes nous dit que prendre la moitié de la longueur de corde vibrante d'une corde théoriquement parfaite double la fréquence des vibrations. Dans le cas d'une guitare, cette longueur de corde se situe entre le sillet de tête et le sillet de chevalet. Cette distance est appelée le diapason de la guitare. La demi-longueur qui permet de doubler la fréquence est la frette n° 12. Si c'est fait correctement, | ||
+ | |||
+ | ====== 2 ====== | ||
+ | |||
+ | **Different scale lengths will create different feel and tones. For example, guitars like the Fender Stratocasters® have a scale length of 25½”, which produces a rich and strong bell-like tone. On the other hand, Gibson guitars often use a scale length of 24¾”. This creates a lower string tension which makes an easier playing feel and a warmer tone. Other guitar manufacturers decided that a scale length of 25” makes a clearer tone than either of the other two “standard” scale lengths. | ||
So with the ability of a guitar maker to come up with their own scale length, the spacing of the frets will have to be recalculated. This is something that luthiers (guitar makers) have been dealing with for hundreds of years. | So with the ability of a guitar maker to come up with their own scale length, the spacing of the frets will have to be recalculated. This is something that luthiers (guitar makers) have been dealing with for hundreds of years. | ||
- | In the past, there was a technique called the rule of 18 which involves successively dividing the scale length minus the offset to the previous fret by 18. While this kind of worked, the tones were off, the higher up the fingerboard the player went. These days, we use a different constant. This constant is 17.817. By using this “new” constant, the 12th fret or octave is at the exact position to be half the scale length of the string. | + | In the past, there was a technique called the rule of 18 which involves successively dividing the scale length minus the offset to the previous fret by 18. While this kind of worked, the tones were off, the higher up the fingerboard the player went. These days, we use a different constant. This constant is 17.817. By using this “new” constant, the 12th fret or octave is at the exact position to be half the scale length of the string.** |
- | Now, these calculations are easy enough to do by paper and pencil or even a simple calculator, it’s just as easy to create a Python program to do the calculations for us in just a second. Once you have the positions, you simply saw a slot for the fret at the correct positions and then hammer in the frets. | + | Différents diapasons vont créer des tonalités et des résultats différents. Par exemple, les guitares Fender Stratocasters® ont un diapason de 25 ½”, ce qui produit un son de cloche riche et fort. En revanche, les guitares Gibson utilisent souvent un diapason de 24 ¾”. Cela crée une tension de corde inférieure, |
+ | |||
+ | Ainsi, avec la capacité d'un fabricant de guitares à proposer son propre diapason, l' | ||
+ | |||
+ | Par le passé, il y avait une technique appelée la règle des 18, qui consistait à diviser successivement par 18 le diapason moins le décalage de la frette précédente. En procédant ainsi, les sons étaient de plus en plus bas au fur et à mesure qu'on allait vers les aigus. De nos jours, on utilise une constante différente. Cette constante est 17,817. En utilisant cette « nouvelle » constante, la 12e frette ou octave est positionnée exactement à la moitié de la longueur de la corde. | ||
+ | |||
+ | ====== 3 ====== | ||
+ | |||
+ | **Now, these calculations are easy enough to do by paper and pencil or even a simple calculator, it’s just as easy to create a Python program to do the calculations for us in just a second. Once you have the positions, you simply saw a slot for the fret at the correct positions and then hammer in the frets. | ||
So, let’s take a look at the program. | So, let’s take a look at the program. | ||
Ligne 25: | Ligne 45: | ||
CumulativeLength = 0 | CumulativeLength = 0 | ||
- | Next we will create a routine (top right) that will be called repeatedly as we “travel down” the fingerboard. We will pass two values into this routine. One is the scale length and the other is the cumulative distance from the nut to the previous fret. | + | Next we will create a routine (top right) that will be called repeatedly as we “travel down” the fingerboard. We will pass two values into this routine. One is the scale length and the other is the cumulative distance from the nut to the previous fret.** |
- | In this routine, we take the scale length, subtract the cumulative distance and assign that value to BridgeToFret. We then take that value, divide it by our constant (17.817), add back in the cumulative distance and then return that value to our calling routine. Remember, we could simply have returned the calculated value without assigning it to a variable name. However, if we ever want to inspect the calculated values, it’s easier to do if we assign the value before we return it. | + | Ces calculs sont assez faciles à faire avec un papier et un crayon ou une simple calculatrice, mais il est tout aussi facile de créer un programme Python pour calculer à notre place en une seconde. Une fois que vous avez les positions, vous sciez simplement une fente pour la frette aux positions correctes et ensuite insérez les frettes au marteau. |
- | Now we will make our worker routine. We’ve done this kind of thing many times in the past. We will pass it the scale length and it will loop for up to 24 frets (range(1,25)). Even if your project has less than 24 frets, you will have the correct positions of all the frets you do have. I chose 24 because that’s the maximum of frets for most guitars. When we get into the loop, we check the fret number (x) and if it is 1, we pass the cumulative length as 0, since this is the first calculation. Otherwise, we pass the last cumulative length in and it becomes the result from the calculation routine. Finally, we print each fret number followed by a formatted version of the cumulative length. | + | Alors, jetons un coup d’œil au programme. |
- | Finally, we have the code that does the prompting for the scale length. I’m sure you will remember the format for the raw_input routine, since we have used it so many times before. Something you might not remember: that raw_input always returns a string, so when we pass it off to the DoWork routine, we have to pass it as a floating point number so the routine will work correctly. Of course, we could simply pass it as a string, but we would have to deal with the conversion in the DoWork routine. | + | Nous voulons créer un programme qui demande le diapason de la guitare (ou de la basse), fait les calculs et ensuite affiche les distances. Les calculs et toutes les longueurs sont tous retournés en pouces, aussi, pour tous nos amis qui utilisent le système métrique, veuillez ajouter les conversions appropriées. Après presque 5 ans, vous devriez être capable de faire cela facilement. |
+ | |||
+ | On n'a pas besoin d' | ||
+ | |||
+ | Diapason = 0 | ||
+ | |||
+ | LongueurCumulee = 0 | ||
+ | |||
+ | Ensuite, nous allons créer une routine (en haut à droite) qui sera appelée à plusieurs reprises au fur et à mesure que nous « avançons vers le bas » du manche. Nous passerons deux valeurs à cette routine : le diapason et la distance cumulée du sillet de tête à la frette précédente. | ||
+ | |||
+ | ====== 4 ====== | ||
+ | |||
+ | **In this routine, we take the scale length, subtract the cumulative distance and assign that value to BridgeToFret. We then take that value, divide it by our constant (17.817), add back in the cumulative distance and then return that value to our calling routine. Remember, we could simply have returned the calculated value without assigning it to a variable name. However, if we ever want to inspect the calculated values, it’s easier to do if we assign the value before we return it. | ||
+ | |||
+ | Now we will make our worker routine. We’ve done this kind of thing many times in the past. We will pass it the scale length and it will loop for up to 24 frets (range(1, | ||
+ | |||
+ | Dans cette routine, on prend le diapason, on soustrait la distance cumulée et on attribue cette valeur à ChevaletAFrette. Nous prenons ensuite cette valeur, divisons par notre constante (17,817), ajoutons à la distance cumulée et retournons cette valeur à notre routine d' | ||
+ | |||
+ | Maintenant, nous allons écrire notre routine de travail. Nous avons fait ce genre de chose à plusieurs reprises dans le passé. Nous allons lui passer le diapason et elle va boucler jusqu' | ||
+ | |||
+ | ====== 5 ====== | ||
+ | |||
+ | **Finally, we have the code that does the prompting for the scale length. I’m sure you will remember the format for the raw_input routine, since we have used it so many times before. Something you might not remember: that raw_input always returns a string, so when we pass it off to the DoWork routine, we have to pass it as a floating point number so the routine will work correctly. Of course, we could simply pass it as a string, but we would have to deal with the conversion in the DoWork routine. | ||
ScaleLength = raw_input(“Please enter Scale Length of guitar -> “) | ScaleLength = raw_input(“Please enter Scale Length of guitar -> “) | ||
Ligne 39: | Ligne 81: | ||
You might wonder what good this program will do if you aren’t going to build a guitar from scratch. It can be valuable when you're looking at buying a used guitar or trying to tweak a guitar with a floating bridge. Also, if you are a guitar player, this might have been something you didn’t know about guitars. | You might wonder what good this program will do if you aren’t going to build a guitar from scratch. It can be valuable when you're looking at buying a used guitar or trying to tweak a guitar with a floating bridge. Also, if you are a guitar player, this might have been something you didn’t know about guitars. | ||
- | Of course, the code is available from pastebin at http:// | + | Of course, the code is available from pastebin at http:// |
+ | |||
+ | Enfin, nous avons le code qui demande le diapason. Je suis sûr que vous vous souvenez du format de la routine raw_input, puisque nous l' | ||
+ | |||
+ | Diapason = raw_input(" | ||
+ | |||
+ | FaireTravail(float(Diapason)) | ||
+ | |||
+ | Vous pourriez vous demander à quoi sert ce programme si vous ne construisez pas une guitare à partir de zéro. Il peut être utile lorsque vous cherchez à acheter une guitare d' | ||
+ | |||
+ | Bien sûr, le code est disponible sur pastebin : http:// |
issue100/programmer_en_python.txt · Dernière modification : 2015/09/04 10:10 de auntiee