8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DDJ-FLX4のPadで手ドラムマシンを作ろう

Last updated at Posted at 2024-12-07

目標

  • Elixirで作る
  • PioneerDjのDDJ-FLX4を使う
  • MIDI(ソフトシンセ)を使う

前提知識

MIDI(ソフトシンセ)

DDJ-FLX4のPad入力

仕様

  • Pad1を押した時 バスドラム
  • Pad2を押した時 スネア
  • Pad3を押した時 ハイハット
  • PLAY/PAUSEを押した時 終了
  • 上記以外は無視

ソース

lib/synth.ex
defmodule Synth do
  @moduledoc """
  Documentation for `Synth`.
  """
  @hi 42
  @bass_drum 36
  @snare 38

  def start() do
    {_, input} = PortMidi.open(:input, "DDJ-FLX4 MIDI 1")
    {:ok, synth} = MIDISynth.start_link([])
    PortMidi.listen(input, self())
    midi_in(input, synth)

    PortMidi.close(:output, input)
  end

  def midi_in(input, synth) do
    receive do
      {^input, [{{144, 11, 0}, _}]} ->
        IO.inspect("end")

      {^input, [{{_, no, 127}, _}]} ->
        drum(synth, no)
        IO.inspect(no)

        midi_in(input, synth)

      _ ->
        midi_in(input, synth)
    end
  end

  def drum(synth, 0), do: play(synth, @bass_drum)
  def drum(synth, 1), do: play(synth, @snare)
  def drum(synth, 2), do: play(synth, @hi)
  def drum(_, _), do: nil

  def play(synth, note), do: MIDISynth.Keyboard.play(synth, note, 200, 127, 9)
end

動作動画

問題点

  • ソフトシンセを使っている為レスポンスが悪い
  • 上記で遅延があるため、実際の手ドラムすると感覚つかめなくてむずい
  • ハード音源あれば解決するかも(SC-88VLあるけどつなぐ手段は今ない為検証できない)
8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?