# [chuck-users] Static data problem (arrays, floats)

David Rush kumoyuki at gmail.com
Tue Sep 15 09:43:39 EDT 2009

```2009/9/15 Andrew C. Smith <acsmith at willamette.edu>:
> Basically, I want a static function that holds a tuning map in it
> (sort of an alternative to mtof).

For what it's worth, I created a Pitchmap class to abstract around
this problem, but I also wanted to have a slightly more complex
mapping from notes to frequencies. I then sub-classed Pitchmap to have
ArrayPitchmap which I use for  certain funky Just and Indian
intonations. As Below

public class Pitchmap {
fun float freq(int spec[]) {
return Math.pow(2, spec[0] / 1200.0); }}

public class ArrayPitchmap extends Pitchmap {
440 => float root;
float notes[];
fun float freq(int spec[]) {
0 => int octave;
if(spec[0] > notes.size()) return root;
if(spec.size() >= 2) spec[1] => octave;
return root * Math.pow(2.0, octave) * notes[spec[0]]; }}

ArrayPitchmap Just2357;
[1.0,
0.14285714285714285,
0.2, 0.2857142857142857,
0.3333333333333333,
0.4, 0.42857142857142855,
0.5, 0.5833333333333334,
0.6, 0.625, 0.6666666666666666,
0.7, 0.7142857142857143,
0.75, 0.8333333333333334,
0.875
] @=> Just2357.notes;

ArrayPitchmap MaGrama;
[1.40625,
1.5,
1.6666666666666667,
1.875,
2.0,
2.1333333333333333,
2.25,
2.5,
2.6666666666666665
] @=> MaGrama.notes;

david rush
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
```