Skip to content

Conversation

@mi-bear
Copy link
Collaborator

@mi-bear mi-bear commented May 11, 2025

技術書典の記事を書くために日本語のコメントいっぱい入っております。

@mi-bear mi-bear self-assigned this May 11, 2025
@mi-bear mi-bear requested a review from sago35 May 11, 2025 12:00
Copy link
Collaborator

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR ありがとうございます。
いくつかコメントしました。 @mi-bear

@mi-bear mi-bear requested a review from sago35 May 12, 2025 14:48
@mi-bear mi-bear requested a review from sago35 May 13, 2025 02:09
Copy link
Collaborator

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

さらに指摘を追加。
だいぶ安定度が増して、演奏しやすくなるはず。

21_midi2/main.go Outdated
}
}

func redraw(d ssd1306.Device, state State) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この行で heap allocs があるので、 ssd1306.Device を global 変数にしたほうが良いです。
音は、画面描画にできるだけ影響されないようにしたいので。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おお...なるほど、勉強になります!

21_midi2/main.go Outdated
colPins[1].Low()
colPins[2].Low()
colPins[3].Low()
time.Sleep(1 * time.Millisecond)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここの time.Sleep() を削ると 1 回あたり 3ms 減らせれるのでかなり演奏が安定します。
参考ソースを以下に起きました。
関数全体を置き換えでよいと思います。

ca298e0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.Sleep が必要なんだと思い込んでた。結果軽快になった感じがします。

Comment on lines 852 to 861
case off2on:
ret = off2on2
case off2on2:
ret = off2on3
case off2on3:
ret = off2on4
case off2on4:
ret = off2onX
case off2onX:
ret = on
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今回は楽器なので off から on にするときは反応早く、 on から off にするときは反応がルーズでもよい、
ただし、少しだけチャタリング対策したい、という形にするとよいです。

現状のソースで off2on は反応が速いので良し。
しかし on2off のタイミングで NoteOff() してるけど、それはチャタリングしている場合は良くない動きになってしまいます。
なので、 on2off は off が連続で何回か続いたとき、という形にするとよいです。
こちらも参考ソースを置きました。
関数全体の置き換えでもよさそう。

ca298e0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、こうしたほうが良いのか。
書き換えました!めちゃ学びや。

@mi-bear mi-bear requested a review from sago35 May 16, 2025 11:53
Copy link
Collaborator

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sago35 sago35 merged commit bd4b393 into main May 17, 2025
1 check passed
@mi-bear
Copy link
Collaborator Author

mi-bear commented May 17, 2025

やったぜー!

@mi-bear mi-bear deleted the added-midi2 branch May 17, 2025 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants