Pure Programmer
Blue Matrix


Cluster Map

Project: Chromatic Scale Frequencies

Compute the frequnecies of the notes in chromatic scale based on the standard piano keys in twelve-tone equal temperament. Print the note names A, A#, B, C, C#, etc. followed by the frequency in Hertz. One command line argument should be passed that indicates the octave on the piano that should be used, 0-7.

See [[Piano key frequencies]]

Output
$ rustc ChromaticScale.rs error: format argument must be a string literal --> ChromaticScale.rs:30:27 | 30 | println!("{}", format!(output_fmt, chromatic_scale[i], octave, frequency)); | ^^^^^^^^^^ | help: you might be missing a string literal to format with | 30 | println!("{}", format!("{} {} {} {}", output_fmt, chromatic_scale[i], octave, frequency)); | ++++++++++++++ error: format argument must be a string literal --> ChromaticScale.rs:35:25 | 35 | println!("{}", format!(output_fmt, chromatic_scale[0], octave, frequency)); | ^^^^^^^^^^ | help: you might be missing a string literal to format with | 35 | println!("{}", format!("{} {} {} {}", output_fmt, chromatic_scale[0], octave, frequency)); | ++++++++++++++ error[E0425]: cannot find value `args` in this scope --> ChromaticScale.rs:15:5 | 15 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> ChromaticScale.rs:16:12 | 16 | octave = Utils.stoiWithDefault(args[1], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> ChromaticScale.rs:16:34 | 16 | octave = Utils.stoiWithDefault(args[1], 0); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `pow` in this scope --> ChromaticScale.rs:19:22 | 19 | let half_step:f64 = pow(2.0f64,1.0f64 / 12.0f64); | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> ChromaticScale.rs:22:16 | 22 | frequency *= pow(2.0f64,(octave) as f64); | ^^^ not found in this scope error[E0277]: the type `[&'static str]` cannot be indexed by `isize` --> ChromaticScale.rs:27:23 | 27 | if chromatic_scale[i].to_string() == "C".to_string() { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[&'static str]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<&'static str>` to implement `Index<isize>` error: aborting due to 8 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc ChromaticScale.rs error: format argument must be a string literal --> ChromaticScale.rs:30:27 | 30 | println!("{}", format!(output_fmt, chromatic_scale[i], octave, frequency)); | ^^^^^^^^^^ | help: you might be missing a string literal to format with | 30 | println!("{}", format!("{} {} {} {}", output_fmt, chromatic_scale[i], octave, frequency)); | ++++++++++++++ error: format argument must be a string literal --> ChromaticScale.rs:35:25 | 35 | println!("{}", format!(output_fmt, chromatic_scale[0], octave, frequency)); | ^^^^^^^^^^ | help: you might be missing a string literal to format with | 35 | println!("{}", format!("{} {} {} {}", output_fmt, chromatic_scale[0], octave, frequency)); | ++++++++++++++ error[E0425]: cannot find value `args` in this scope --> ChromaticScale.rs:15:5 | 15 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> ChromaticScale.rs:16:12 | 16 | octave = Utils.stoiWithDefault(args[1], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> ChromaticScale.rs:16:34 | 16 | octave = Utils.stoiWithDefault(args[1], 0); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `pow` in this scope --> ChromaticScale.rs:19:22 | 19 | let half_step:f64 = pow(2.0f64,1.0f64 / 12.0f64); | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> ChromaticScale.rs:22:16 | 22 | frequency *= pow(2.0f64,(octave) as f64); | ^^^ not found in this scope error[E0277]: the type `[&'static str]` cannot be indexed by `isize` --> ChromaticScale.rs:27:23 | 27 | if chromatic_scale[i].to_string() == "C".to_string() { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[&'static str]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<&'static str>` to implement `Index<isize>` error: aborting due to 8 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc ChromaticScale.rs error: format argument must be a string literal --> ChromaticScale.rs:30:27 | 30 | println!("{}", format!(output_fmt, chromatic_scale[i], octave, frequency)); | ^^^^^^^^^^ | help: you might be missing a string literal to format with | 30 | println!("{}", format!("{} {} {} {}", output_fmt, chromatic_scale[i], octave, frequency)); | ++++++++++++++ error: format argument must be a string literal --> ChromaticScale.rs:35:25 | 35 | println!("{}", format!(output_fmt, chromatic_scale[0], octave, frequency)); | ^^^^^^^^^^ | help: you might be missing a string literal to format with | 35 | println!("{}", format!("{} {} {} {}", output_fmt, chromatic_scale[0], octave, frequency)); | ++++++++++++++ error[E0425]: cannot find value `args` in this scope --> ChromaticScale.rs:15:5 | 15 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> ChromaticScale.rs:16:12 | 16 | octave = Utils.stoiWithDefault(args[1], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> ChromaticScale.rs:16:34 | 16 | octave = Utils.stoiWithDefault(args[1], 0); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `pow` in this scope --> ChromaticScale.rs:19:22 | 19 | let half_step:f64 = pow(2.0f64,1.0f64 / 12.0f64); | ^^^ not found in this scope error[E0425]: cannot find function `pow` in this scope --> ChromaticScale.rs:22:16 | 22 | frequency *= pow(2.0f64,(octave) as f64); | ^^^ not found in this scope error[E0277]: the type `[&'static str]` cannot be indexed by `isize` --> ChromaticScale.rs:27:23 | 27 | if chromatic_scale[i].to_string() == "C".to_string() { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[&'static str]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<&'static str>` to implement `Index<isize>` error: aborting due to 8 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`.

Solution