質問

このチャックコードを持っています:

"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(またはより良いfloat)に変換したいです。

どうすればいいですか?

役に立ちましたか?

解決

atoiライブラリのatofStdを使用します。0~127(MIDIベロシティ)から0~1.0の間のフロート(ユニットジェネレータにははるかに便利)から翻訳したいとしましょう。

Std.atoi(fio.readLine()) => int midi_velocity;
midi_velocity/127.0 => float velocity;
<<< velocity >>>;
.

は、10の入力のために0.078740 :(float)を印刷する必要があります。

またはフロートにまっすぐに進みたい場合:

Std.atof(fio.readLine()) => float velocity;
<<< velocity >>>;
.

10.000000 :(float)を印刷します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top