题
我有这个查克代码:
"examples/vento.txt" => string filename;
FileIO fio;
// open a file
fio.open(filename, FileIO.READ);
// ensure it's ok
if(!fio.good()) {
cherr <= "can't open file: " <= filename <= " for reading..." <= IO.newline();
me.exit();
}
fio.readLine() => string velocity;
fio.readLine() => string direction;
.
文本文件包含:
10
12
.
(每分钟用python更新)
我想将速度和方向转换为int(或更好的浮点)。
如何这样做?
解决方案
在atoi
库中使用atof
和Std
。假设您想从0-127(MIDI速度)转换为0到1.0之间的浮点(更方便的单元生成器):
Std.atoi(fio.readLine()) => int midi_velocity;
midi_velocity/127.0 => float velocity;
<<< velocity >>>;
.
应该打印10个输入的生成频率agdode。
或者如果你想直接浮动:
Std.atof(fio.readLine()) => float velocity;
<<< velocity >>>;
.
哪个打印生成的。
不隶属于 StackOverflow