Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@kmizuno0211

Elixir~Enum.zipでドラムシーケンサー!~

ここまでのあらまし

Enumやforを使ったマップリストからのデータ呼び出しを簡単に復習しました。

今回の試み

バスドラム=bassを"Don"
ハイハット=hihatを"Tik"、"tik

これをfor文を使って順列組み合わせを作っていきます。


iex(9)> bass = ["Don","Don","Don","Don"]
["Don", "Don", "Don", "Don"]
iex(10)> hihat = ["Tik","tik","tik","tik"]
["Tik", "tik", "tik", "tik"]
iex(11)> for b <- bass, h <- hihat do
...(11)> [b,h] end
[
  ["Don", "Tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "Tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "Tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "Tik"],
  ["Don", "tik"],
  ["Don", "tik"],
  ["Don", "tik"]

なんと。。全拍でバスドラムとハイハットが鳴ってしまいました。

改善

Enum.zipを使います。

iex(1)> bass = ["Don","-","-","-"]
["Don", "-", "-", "-"]
iex(2)> hihat = ["Tik","Tik","tik","tik"]
["Tik", "Tik", "tik", "tik"]
iex(3)> Enum.zip(bass,hihat)
[{"Don", "Tik"}, {"-", "Tik"}, {"-", "tik"}, {"-", "tik"}]

ドン、チッ、チッ、チッ、という刻みのパターンができました!
無論音がなっているわけではないので、要はElixirをシーケンサーに実装するたたき台のようなものに過ぎないかもしれませんが...ワクワクしますね!

これからの試み

あたらしく登場したEnum.zipを使って、登場する各要素の狙った部分を加算したり自由に演算できるような学習を想定しています。
うまずたゆまず、頑張ります。
Kento Mizuno

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
6
Help us understand the problem. What are the problem?