編集履歴一覧に戻る
Yosukeのアイコン画像

Yosuke が 2022年09月22日11時52分52秒 に編集

初版

タイトルの変更

+

Spresenseと身近なもので作る誰でも弾けるピアノ🎹

タグの変更

+

spresense

メイン画像の変更

メイン画像が設定されました

記事種類の変更

+

製作品

本文の変更

+

【2022年 SPRESENSE 活用コンテスト】< エンタメ部門 >にエントリーするための作品として `誰でも弾けて、誰でも作れて、誰でもデコれるピアノ🎹`を作ってみました。 以下、作品のコンセンプトと部品表、作成方法、回路図、ソースコードです。 # コンセプト `弾き語り`をされたことがあるでしょうか。 楽器を弾きながら歌うわけですが、 楽器の演奏と歌唱というマルチタスクを 同じ力配分でこなすのは、**初心者には結構難しい**😖です。 弾き語りを始めようとするときには、ピアノでもギターでも、 まずは`コード(和音)の押さえ方の覚え`、 `コードの移行がスムーズにできるように繰り返し練習`する必要があります。 私も最初は頑張って練習していたのですが、 次第に面倒なことはすっ飛ばして、**一足飛びに気持ちよく歌えるようになりたい**と思うようになりました。 そこで、作ったのが`初心者が適当に弾いても良い感じの伴奏になる楽器`です。 # コード進行をSpresenseのメモリに保存する方法 まずは、弾きたい楽曲のコード進行を自分で覚えなくて良いように、 `計算機(今回はSpresense)に記憶`してもらいます。 例えば、ある楽曲のコード進行が 【F#m→AonE→D→Bm→DonE→E7→A→AonG#→F#m7→AonE→D→...】 と続く場合、これを計算機に取り込みたいわけですが、 **このままでは計算機が認識しにくい**ので、 計算機が扱いやすいデータに変換(エンコード)してあげる必要があります。 そこでコード進行を0,1などの数字で表せるように工夫します。 --- まず楽曲全体にユニークなコードがいくつあるかを確認し、 それぞれのコードに0から順番に番号を割り当てていきます。 先ほどのコード進行の場合、 | コード名 | コード番号 | |:---:|:---:| | F#m | 0 | | AonE | 1 | | D | 2 | | Bm | 3 | | DonE | 4 | | E7 | 5 | | A | 6 | | AonG# | 7 | | F#m7 | 8 | | 続く | 続く | となります。 このテーブルに従って、先ほどのコード進行を番号に置き換えますと、 【0→1→2→3→4→5→6→7→8→1→2→...】 となりますので、配列に入れてメモリに保存します。 --- コード進行と一緒に、上のテーブルも保存しておかないと、ただの数字の羅列になってしまいますので、テーブルも数字に置き換えます。 そのために、更にテーブルを2つ用意します。 1つ目のテーブルは、CからBまでの12音に1から12までの数字を割り振ったものをマクロで定義しておきます。 ```spresense:コード符号化の例 #define C 1 #define CS 2 #define DF 2 #define D 3 #define DS 4 #define EF 4 #define E 5 #define F 6 #define FS 7 #define GF 7 #define G 8 #define GS 9 #define AF 9 #define A 10 #define AS 11 #define BF 11 #define B 12 ``` もう一つは、メジャーやマイナーなどのコードを決定づける修飾子に任意の番号をつけたマクロです。 ```spresense:コード符号化の例 #define M(メジャー) 1 #define mi(マイナー) 2 #define SUS4(サスフォー) 3 #define DIM(ディミニッシュ) 4 #define AUG(オーギュメント) 5 #define F5(フラットファイブ) 6 ...続く ``` これらのテーブルに従って、コードネームのテーブルを数字に変換すると、 | コード名 | コード番号 | |:---:|:---:| | 7, 2, 0(F#m) | 0 | | 10, 1, 5(AonE) | 1 | | 3, 1, 0(D) | 2 | | 12, 2, 0(Bm) | 3 | | 3, 1, 5(DonE) | 4 | | 続く | 続く | となり、これを配列に格納して、メモリに保存します。 これで`コード進行を計算機に取り入れる`ことができました。 ついでに、弾き語りに便利なテーブルをもう2個追加しておきます。 1つは曲のタイトルと歌手名(グループ名)をまとめたテーブル。 もう1つは、Aメロ、Bメロ、サビのような曲の構成上の区切りのテーブルです。 サビから歌いたい時や、2番だけ歌いたい時など、 希望した位置のコードから始められるように、このテーブルを使います。 # 音階の割り当て方 次に、コード(和音)の押さえ方を覚える手間を省けるよう、 `計算機に自動で音階を鍵盤に割り当て`てもらいます。 ![キャプションを入力できます](https://camo.elchika.com/c056083489ed5b101cd57bd65f011cf329dc3d5a/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f37643535323831362d643462392d346630322d393965312d326530613633626165383634/) 上の図のように鍵盤は3つのパートに分かれており、説明上分かりやすいように白⬜、黄色🟨、紫🟪で塗り分けてみました。 図の左端の2つの白鍵は**アプローチノート**を割り当て、コードを移行する際に使うとプロの演奏っぽくなれます。 図の黄色い鍵盤は**コードの構成音**が割り当てられます。 例えば、F#mの場合、ファ#、ラ、ド#が左から低い順に並びます。 図の紫の鍵盤には**テンションノート**が割り当てられます。 テンションノートは、与えられたコードを出来るだけ邪魔せず、 オシャレな和音になるように割り当てられます。 ただし、3和音のマイナーコードの場合は7thノートが割り当てられますので、F#mの場合は、ミとなります。 つまり、テンションノートの鍵盤には7th系のノートが割り当てられることがあります。 が、何の音が出ているかは考えなくても、押せばだいたいおしゃれな和音にできます。 テンションノートも左から低い順に並びます。 これで`適当に鍵盤を押しても良い感じの和音が出せる`ようになりました。 # コード進行の進ませ方 あとは、**コード進行を歌に合わせて進ませる**だけです。 進ませ方も色々試しましたが、今のところ鍵盤を上下の2段にして、 交互に行き来する方法が最善の方法だと考えています。 ![キャプションを入力できます](https://camo.elchika.com/48777605cfc5ed24175bb5c59e0c5292921c807e/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33616636633865342d313733652d346435362d613633612d346330373762356435323035/) 分かりやすいように下の鍵盤を白に、上の鍵盤を水色にしてみました。 まず曲の始めは必ず下の鍵盤から始まります。 そして次のコードに移るときには上の鍵盤を押します。 さらに次のコードに移るときは下の鍵盤に戻ります。 そして**上、また下と行ったり来たりする**とコード進行が進んでいきます。 # 説明と実演の動画 この辺りの説明を動画でまとめてみました。是非ご覧ください。 @[youtube](https://youtu.be/lcG-nxLJax0) # コントロールボタン コントロール用のボタンとして8個ボタンを用意しています。便利な機能盛りだくさん。 | ボタン名 | 機能 | |:---:|:---:| | DECREMENT_BUTTON | このボタンを押しながらほかのボタンを押すと別の機能が使えます | | CHANGE_CHORDCHANGINGMODE | コード切り換え方式の切替を行います。今回は使用しません。 | | CHANGE_INDEX | コード進行を1つ進めます。DECREMENT_BUTTONを押しながら押すと、コード進行を1つ戻します。 | | CHANGE_KEY | 曲のキーを1つ上げます。DECREMENT_BUTTONを押しながら押すと、キーを1つ下げます。 | | CHANGE_SONG_STRUCTURE_INDEX | 曲の構成番号を1つ進めます。DECREMENT_BUTTONを押しながら押すと、曲の構成番号を1つ戻します。 | | CHANGE_TRACK | 内蔵されてる曲のトラック番号を1つ進めます。DECREMENT_BUTTONを押しながら押すと、内蔵されてる曲のトラック番号を1つ戻します。 | | CHANGE_KEYLAYOUT | 鍵盤配列のモードを切替えます。今回は使用しません。 | | CHANGE_PLUS_MODE | DECREMENT_BUTTONを押しながら押すと、内蔵されてる曲のトラック番号を5つ進ませます。 | # 作り方 コード(和音)の勉強も練習もしたくない。 そういう面倒なことは全部計算機(今回はSpresense)に任せたいという方は、 是非以下の手順を参考に作ってみてください。 # 使用したもの できるだけ**誰でも作成が可能**なように`100円均一で売られている素材、工具`を中心に制作いたしました。 | 素材名・部品名 | 個数 | |:---:|:---:| | カラーボード10mm厚(ダイソー) | 数枚 | | カラーボード5mm厚(ダイソー) | 数枚 | | はさみ | 1挺 | | カッター | 1本 | | 銅線0.28mm(ダイソー) | 数個 | | 銅線0.55mm(ダイソー) | 1個 | | 精密作業用はんだ(ダイソー) | 数本 | | はんだごて | 1本 | | 木工用ボンド(ダイソー) | 1本 | | 2リングファイルフォルダー(ダイソー) | 1冊 | | 銅箔テープ幅38mm長さ5m(Nitto) | 2個 | | 薄い紙製両面テープ(ダイソー) | 1個 | | 厚い両面テープ(ダイソー) | 1個 | | 方眼のついた工作用紙5枚入り(ダイソー) | 1つ | | のり | 任意 | | プリンター | 任意 | | SPRESENSE 本体 | 1つ | | SPRESENSE 拡張基盤 | 1つ | | 長めのブレッドボード | 2つ | | 短いブレッドボード | 1つ | | ジャンパワイヤ | 任意 | | 小信号用ダイオード 1N4148 | 128本 | | 74HC138(ロジックIC) | 1個 | | タクトスイッチ | 8個 | # 筐体のつくり方 筐体は、手に入れやすく加工のしやすさからダイソーの**カラーボード**を使用することにしました。 ![キャプションを入力できます](https://camo.elchika.com/f5e99fc9b9138350d1e3c35eac39c2624be70105/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f34313633343564632d626337352d346631392d386164632d336366666634346465373064/) 上のカラーボードを横に二枚並べて、土台となる横52.6cm、縦17cmに切り取ります。 以下の2枚のPDFをダウンロードして、プリントアウトします。 [自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 底面 pt.1.pdf](http://keiopress.coolblog.jp/自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 底面 pt.1.pdf) [自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 底面 pt.2.pdf](http://keiopress.coolblog.jp/自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 底面 pt.2.pdf) 先ほど切り出したカラーボードに、のりなどの接着剤を使い貼り付けます。 ![キャプションを入力できます](https://camo.elchika.com/5b7b26bc1710be15f616eacd96377e34f27027db/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33353433663939352d336361642d346334372d613832382d333534386566653939373537/) 鍵盤と鍵盤の間の横2mm縦10cmの部分を全てカッターで切り落とします。 横10cm縦2cmをカラーボードから切り出し、写真のように土台の両サイドに接着します。 今度は5mm厚の薄いカラーボードから、中面となる横54.6cm、縦10cmを切り取ります。 以下の3枚のPDFをダウンロードして、プリントアウトします。 [自作ピアノ【据え置き】54鍵(2.2cm×10cm)0.2cm間隔 中面 pt.1.pdf](http://keiopress.coolblog.jp/自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 中面 pt.1.pdf) [自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 中面 pt.2.pdf](http://keiopress.coolblog.jp/自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 中面 pt.2.pdf) [自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 中面 pt.3.pdf](http://keiopress.coolblog.jp/自作ピアノ【据え置き】54鍵(2.2cm×10cm)  0.2cm間隔 中面 pt.3.pdf) そして先ほどの中面に貼り付けます。 鍵盤と鍵盤の間の横2mm縦3cmの部分を全て切り落とします。 両端に横3cm縦1cmのカラーボードを接着します。 すると下のような写真になります。 ![キャプションを入力できます](https://camo.elchika.com/5870f70d0acbfc7f07795fa2a48da1b031c592dc/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f38393036663535322d316630642d346132342d396638322d363465393439333263336661/) 中面の裏に固めのものを貼っておくと良いかもしれません。 ![キャプションを入力できます](https://camo.elchika.com/a646d6cf2329f0112547aa5415e6bb198777c415/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f63303630376639642d623331382d346638622d393430342d326135313532323833616564/) 鍵盤と鍵盤の間の2種類の間仕切りを作っていきます。 1つ目は、横2cm縦2cmの工作用紙を数枚重ねてセロテープで固定したもの(26個)。 ![キャプションを入力できます](https://camo.elchika.com/92641f25059f9d39899f6cd7e41389282f1e270e/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f39643237333234372d633764662d343961322d396564352d356639646364363765643439/) 2つ目は、横3cm縦3.7cmの工作用紙を数枚重ねてセロテープで固定したもの(26個)。 ![キャプションを入力できます](https://camo.elchika.com/e3f6084d16535d80cf65196f92608c5ed259b3e7/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32383530383861342d663863352d346465322d396438352d393238393032323738643265/) この間仕切りを土台に差していきます。小さい間仕切りは手前に。 ![キャプションを入力できます](https://camo.elchika.com/2586355221ed43e077cb998a854f44247df00c7c/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f30656361613264372d336232302d343261372d383562612d623738313530373239383261/) 大きい間仕切りは奥に。 ![キャプションを入力できます](https://camo.elchika.com/0e9a0975e9d90b059eff70a71c4a762b54971650/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f34343638313630382d623534642d346261632d626436662d613633613466623762613939/) 最後にカラーボードから、上面となる横54.6cm縦3cmを切り取ります。 ![キャプションを入力できます](https://camo.elchika.com/61c6a9ab36a9abbb73c607c813fa6f3c54407b84/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33313266393233632d656531382d346664662d623137372d353034616238393838373365/) これで筐体は完成です。 # 鍵盤のつくり方 鍵盤も、**手に入れやすく加工のしやすさ**から`ダイソーの2リングフォルダーファイル`を使わせていただきました。 まずは、以下のリンクからダウンロードしたPDFをプリントアウトして、 2リングフォルダーファイルに貼ります。 [自作ピアノ【据え置き】54鍵(2.0cm×10cm)  0.2cm間隔.pdf](http://keiopress.coolblog.jp/自作ピアノ【据え置き】54鍵(2.0cm×10cm)  0.2cm間隔.pdf) ![キャプションを入力できます](https://camo.elchika.com/9167ce17ea6390c87d5230ce7fe864fc25af82d5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f63303535633937642d363432372d343135382d386664622d333832353132613632633537/) ![キャプションを入力できます](https://camo.elchika.com/313800574efa8292327876489854fb4fdbe6c4d1/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32386637313131392d393831392d346139362d396164302d343135316636326634386562/) そして、PDFの概形に沿って、4種類の鍵盤を切り出します。 ![キャプションを入力できます](https://camo.elchika.com/af0c6c465f5229a2ff01718001905af239062320/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f62303464356539372d626637392d343537612d393139342d323036383864323366386432/) # スイッチの作り方 次に鍵盤の下に設置するスイッチを自作していきます。 市販のキーボードは**2つのスイッチ**を各鍵盤に設置して、`どのくらいの強さで鍵盤が押されたか`をセンシングしています。 そのため、自作キーボードもそれに倣って、タクトスイッチのような押しボタンスイッチを使いたいところなのですが、キーボードを試作したところ、鍵盤を押すたびにカチッカチッと音がして演奏の邪魔になるほか、薄くもできないということが分かったので、`スイッチも自作`することにしました。 ~~スイッチまで自作する猛者は自分だけだろうと自負しております😅(笑)~~ さて、出来るだけ身近にあるもので目的に合うスイッチを作ろうと、 実験を重ねた結果、**ダイソーの工作用紙と銅線、それと銅箔テープ**の組み合わせが最適解だろうという結論に至りました。 ポイントは2つのスイッチを垂直に重ねた構造にすることで、鍵盤を押した時に、 それぞれのスイッチがONになり、その時間の差分をとって、どれだけ強く押されたかをセンシングすることです。 時間が短ければ強く押されているので、その時間に応じて大きな音量(ベロシティ)で音を出し、時間が長ければ弱く押されているので、その時間に応じて小さな音量で音を出す仕組みです。 以下、大きなスイッチと小さなスイッチの作り方です。どちらのスイッチも寸法が違うだけで基本的な作り方は一緒です。 小さなスイッチを例に説明します。 まず工作用紙から横1cm縦4cmを2つ切り出します。 一方は上用で、もう一方は下用となります。 ![キャプションを入力できます](https://camo.elchika.com/3043b26cc8c140910d88a44ea995fb75469b6326/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f37353363633035652d396263632d343533622d396433312d663061643938353333623036/) それぞれ真ん中で折り曲げます。 ![キャプションを入力できます](https://camo.elchika.com/01c1c071b0f7836450d271ab6f1c7eacaf3394f5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f37313732653834342d306664322d346464642d623337332d316331313933333762336465/) 上用から作っていきます。 銅箔テープから長さ3.5cm幅1mmを8本切り出します。 ![キャプションを入力できます](https://camo.elchika.com/61789abb256073edb5ad9a664e381e1ca7360e85/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f37613662663139392d393165322d343466352d393735642d633838393864306333653462/) これを上用の工作用紙に写真のように貼っていきます。 ![キャプションを入力できます](https://camo.elchika.com/16c73eb96bfa50749c320546ca65f41f9f5bb9a6/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f34613639383830652d306564302d346265662d396666642d363235306230663733623339/) これを全部で4本貼っていき、写真のように2本を短くします。 ![キャプションを入力できます](https://camo.elchika.com/4926d89938382ba973c3429c8e2208384376d644/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f62303439653166652d373938312d343638392d396537302d643435373163343064626566/) 裏返します。 ![キャプションを入力できます](https://camo.elchika.com/d76a617fc3a329fe3d878c4e8fa3085eb64524c0/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f31386663383234352d353836652d343935632d623661312d346630643137333561616664/) 短いテープを折り曲げます。 ![キャプションを入力できます](https://camo.elchika.com/a9b81f6ace8bd74c6fb7c0ddb33b60f2a6c9f6aa/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f62616234653532622d633536652d346635322d383737362d666363316461356635333665/) 折り曲げた先を銅線でつなぎます。はんだごての使い方に注意をしてください。 ![キャプションを入力できます](https://camo.elchika.com/6dc028f66ee0ab65f319b59cec9be9b03021c0d5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61626133303732632d336636302d346365652d393433652d653066343836333564353031/) つないだはんだに更に20cmの銅線を写真のようにつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/8a7aebc804f4f8497231d6b10e89836cd5e18b98/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f37316333636438342d363061322d346532392d613038392d306531353362303338376234/) ![キャプションを入力できます](https://camo.elchika.com/b0454fb7782995a019695e9bb81202874bea5fea/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f64373265643263352d353565342d343038382d613830312d613661373530643663343166/) 20cmの銅線の根元に短いセロテープを貼り、半分に折り返して銅線を密封します。 ![キャプションを入力できます](https://camo.elchika.com/768e6aa98122158b219ab744eabaa45ba255f814/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f39363931313236382d393638632d343639382d623634612d303736356136636364306564/) 短いセロテープに接続する形でセロテープを貼り、全線を保護します。 ![キャプションを入力できます](https://camo.elchika.com/0fc5dd3da6fa0d2b1f4de1bd4541a485ef925720/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f31643436393438632d356431662d343834642d626436342d643432353637393936336337/) 銅線の先端は6~7mm出しておきます。 ![キャプションを入力できます](https://camo.elchika.com/3282c2e268d07a2f4fe0b064a24c64ba0bfeb6b4/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32613336653533642d666532382d346562322d623639302d353239313632623163363535/) 余分なセロテープをカットして、細くしておきます。 ![キャプションを入力できます](https://camo.elchika.com/b8f23a0c7d6a34851bf49d9934c0870e22dac8a1/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33653230613865332d316363332d343738382d616237612d336362653866653336653666/) 先ほどハンダ付けした箇所にセロテープを貼って保護しておきます。 ![キャプションを入力できます](https://camo.elchika.com/ae534fc79294176c5d84b5bc78d7ebaec1358918/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f63636430643738622d653732372d346431622d626436352d313938343364353232363266/) 今度は長い方の銅箔テープを折り曲げます。 ![キャプションを入力できます](https://camo.elchika.com/fbfdebe470f819f838cd52f31b8be176efae8b9f/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f65633364626236332d353330332d343333662d623663632d623366313239373438326361/) 折り曲げた先に銅線をはんだでつなげます。 ![キャプションを入力できます](https://camo.elchika.com/d491398b545b5f0fe9be9f00a19c6959153b3e7b/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32323637326438632d626630652d343533302d386562392d326237376165363037313236/) つなげたっ銅箔テープのどちらかに写真のようにハンダ付けして2cmほどの銅線をつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/6e1e34381dc01af17fcd230a7ba218e738215045/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f34666363383130332d346431362d343339352d386231382d316435303233313134313737/) そこにセロテープを貼り、面を保護します。 ![キャプションを入力できます](https://camo.elchika.com/40465887488bcf2d9dc1e8f4dbfec42cb8310f39/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66376163383934322d643433642d343966322d613231352d366566343162616233383264/) 裏返します。 ![キャプションを入力できます](https://camo.elchika.com/dd67a178c6f827be349bdee5d66e2f5fbd4daf52/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66343834633936362d303763342d346239632d386638362d356666303036376237656337/) 銅箔テープから1cm×1.9cmのテープを切り出します。 ![キャプションを入力できます](https://camo.elchika.com/a0aa64b7e454ef4fe1197fa24a89339392ae08d2/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32613931353138642d613130362d343935322d623961612d656432383766363435343330/) これを写真のようにスイッチに貼ります。 ![キャプションを入力できます](https://camo.elchika.com/4b321509632bda4e7520a94879188392c7ab6294/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f38333333656566302d633164322d346539642d396637302d633361393561396638646165/) 端から銅箔テープがはみ出ていたら綺麗にカットしておきます。 ![キャプションを入力できます](https://camo.elchika.com/445b769d0b79bf01af20ff15a72d34e53cf4eb57/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f65343031393763612d343535612d343963312d383363642d303739393964323065656636/) これで上用のスイッチは完成です。あとで、下用のスイッチと合体させるので、保管しておきます。 下用のスイッチを作っていきます。 こちらも上用のスイッチと同様に、銅箔テープを貼っていきます。 ![キャプションを入力できます](https://camo.elchika.com/b68582ba92d7aeb6dc9e5acd56841b1c3c1e197b/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f30336563383765372d353364322d343738312d613066352d303065616466623863646463/) 写真のように2本は短くします。 ![キャプションを入力できます](https://camo.elchika.com/dbc70813f373b7dd58363d697e2d8daff2776635/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f38316261393965382d663037632d346631662d616565632d376134336132393363383439/) 裏返して、短い銅箔テープを折り曲げます。 ![キャプションを入力できます](https://camo.elchika.com/ebdc8c2fc28e11b231765ae1be29c130bbd649f1/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35623964343463302d363066652d346332382d383134652d333038336465626462636465/) 銅線でつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/fd00a92d1130beb17388ecca9eca47f89a8e8b65/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f39613539613335302d383634372d346531382d386361302d653336396464353233646530/) 銅箔テープの片方に20cmの銅線をつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/ab97c9a21c6127bc5a86cf2ef8f28cf8f7162ae0/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f65393038306235302d323032312d346438612d613533372d653361616363383132393161/) 銅線の根元に短いセロテープを貼ります。 ![キャプションを入力できます](https://camo.elchika.com/a7abe0f811623ab542b9b6a5ef7ca71bc0218638/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f36393262623236612d643739382d343363342d616566362d313762636436636237316461/) セロテープを継ぎ足す形で、前線をセロテープで密封します。先端は少し残しておきます。 ![キャプションを入力できます](https://camo.elchika.com/18722d141478aa761eb54d049dbe5fa9c039c46d/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f34626366396233302d663035332d343164392d623866302d366561306266616262653730/) 余ったセロテープはカットして、細くしておきます。 ![キャプションを入力できます](https://camo.elchika.com/0cf9fb53f9cb42f843c505e729a91125da833eb0/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f64316532646336662d303139382d343737312d626630312d303738616539386138656464/) 上にセロテープを貼って、保護します。 ![キャプションを入力できます](https://camo.elchika.com/99376dd7375bddb0f4eb358e93a0b366ea20e3f1/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35343030363562342d343731642d343433662d626162382d623434353334393133303534/) 長い方の銅箔テープを折り曲げます。 ![キャプションを入力できます](https://camo.elchika.com/170db7f20ba36829d954783373f896721c767aae/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32663664316436662d336466372d346366332d386262322d626662656637393136333465/) 先端を銅線でつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/6a8e4df0fa2ff07194f4a73d3fb04b9e09964026/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f30313631646565322d626131632d343465332d386532652d333235346638386532386133/) 裏返します。 ![キャプションを入力できます](https://camo.elchika.com/ce06a634aae02506e2e184ae5f3610143fbc1395/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f62663930343665662d646232352d343866382d386264662d393563376138373864386365/) 横1cm縦1.9cmの銅箔テープを貼ります。 ![キャプションを入力できます](https://camo.elchika.com/513b786b9e7b2fdb07b80f65ea1994b4f7e9c2e8/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f34633662656334342d353365312d346134382d613061332d333164616536656261663263/) 裏から見ると銅箔テープがはみ出ているのが分かりますね。 ![キャプションを入力できます](https://camo.elchika.com/e909fb3615a1f4c050e458b5c0656a6adf3db6dd/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f63383632316437352d643162362d346165352d626135322d616661636133346364303636/) 綺麗にカットします。 ![キャプションを入力できます](https://camo.elchika.com/d8cb2adfe22fac51504ec55b6ee1aff07521485e/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61613463393462362d363630662d343664372d623732352d306630303564323139643662/) この面に両面テープを貼ります。 ![キャプションを入力できます](https://camo.elchika.com/d2ce414f775e9e4152a66db396b7a3933153a843/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f62326235366335392d643738662d343562352d383862352d643330636661373864653531/) 上用のスイッチと合体させます。 ![キャプションを入力できます](https://camo.elchika.com/e9785acc3c41fb4d52cf4cd9cf0a25890e3f3245/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61623531393964342d636465352d346439382d386333612d656539633031363936636338/) 上用のスイッチから飛び出した銅線を下用のスイッチのはんだにつなげます。 ![キャプションを入力できます](https://camo.elchika.com/d0bc0640183b20a57a6790b6f0df638b38c1bec7/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f64636362396636302d616263332d343333332d383535372d323266366461623362623034/) はみ出た銅線をカットしておきます。 ![キャプションを入力できます](https://camo.elchika.com/153d9ea528330bbea08392515c1d707322318d11/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61393132303232362d313239362d343430372d386237362d376534653463383837393666/) 今つないだ銅箔テープに更に20cmの銅線をつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/074eb5385b3c3aeb2d8f1218aa66fa9ecb2c8710/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33326137313632312d353533612d343864302d623064342d666466636236343331373563/) 銅線をセロテープで保護します。 ![キャプションを入力できます](https://camo.elchika.com/7aa75fb15941e4d68ceed76ebbfcb4b2db95d77d/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66343761306330352d643739372d343962332d623964622d623832373564633430353833/) 先端を少し残しておきます。 ![キャプションを入力できます](https://camo.elchika.com/6ae52e494de07dcc9663f36b3a1cca9de63dba9d/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35313565623734642d333065342d346130372d613961642d643536656564393536653331/) 余ったセロテープをカットして、下用のスイッチにセロテープを貼って保護します。 ![キャプションを入力できます](https://camo.elchika.com/6343d4bba7e6089a021a3e1517f0f2422f7b629e/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f36613566336533332d343636332d346233382d393337302d373939633262643063326666/) **ようやく完成!!** 横から見た写真 ![キャプションを入力できます](https://camo.elchika.com/59302f024b56538c0e7d71c8d17b4009be5a605b/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f64373532356334612d653764382d346136632d623862382d373564616661633861323032/) 斜め上から見た写真 ![キャプションを入力できます](https://camo.elchika.com/30a47afdc6f2c00305162c50aeab2d61c5a30305/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f62313833633065662d333761332d346265322d626662662d386363306231313566636432/) ++正直このスイッチに一番頭を使いましたし、一番時間がかかりました。最初に色々なスイッチを自作して実験して、何十個とうまくいかないスイッチを作り、ようやくこの形でいけそうとなってから、54個のスイッチを1個1時間かかって作りました。しかし、時間と労力をかけただけあって、ただ単にノートオン、ノートオフをするだけのスイッチではなく、どのくらいの強さで押されたかをセンシングできる納得いくスイッチに仕上がりました。++ # 電子回路について 回路の方は、**SPRESENSE**を中心に、ICは**74HC138**のみを使い128個のスイッチをキーマトリクス回路で実装いたしました。 スイッチ1個につきダイオードを1本ずつ付けて、**スイッチの同時押し**を可能にしています。入力の方も74HC165などでエンコードして、ピンを節約しようかと思ったのですが、SPRESENSEは使えるI/Oピンが沢山あったため、結果的に74HC138のみとなり、つくりやすく出来たかと思います。ただ、今回、回路図のSW_0-1~SW_0-9とSW_0-64、SW_0-65は使っていませんのでご注意ください。 # 回路図 ![キャプションを入力できます](https://camo.elchika.com/fc500f2fe3e845b1249e1667951c87b1a895ce4f/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61633834313036632d333265662d343561392d383534662d613938646632613264396436/) ![キャプションを入力できます](https://camo.elchika.com/a6c6cddb08b59ecfde4774dc551993f531a783ff/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61613131386633302d633437392d346237642d613530662d373165306564663966363138/) ![キャプションを入力できます](https://camo.elchika.com/153728d08dc0c31765ad9225b9dffcc679bbd16b/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f63666563613361662d316232622d346636302d383366352d396665326637343965333839/) # 筐体、スイッチ、電子回路の組み上げ ピアノを仕上げていきます。 土台の上に両面テープを貼り、スイッチを設置していきます。 ![キャプションを入力できます](https://camo.elchika.com/3dc80d17b8624b8b6e9b119ff05201611de71ff5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35636263636330342d313333612d343035362d396561352d653238386665363564303666/) スイッチの上に両面テープを貼った鍵盤を乗せて、固定します。 ![キャプションを入力できます](https://camo.elchika.com/c3cf6887573c4af3752fb2a809f3f3f4438a1343/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f39353333313036392d666633312d343533382d623464642d343438646562663364613961/) ![キャプションを入力できます](https://camo.elchika.com/977290d563c2394e4f6456cccefbca144d363e36/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f31663036306466302d393334642d343665612d386637332d353632363465613162346532/) スイッチと鍵盤を設置したら、スイッチの銅線2本を74HC138に接続します。 ![キャプションを入力できます](https://camo.elchika.com/90ceefc5afa49825762e602cd3b58faa6fedf2cf/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35313635323939322d373763352d346530622d613065392d366339353037363861373836/) 銅箔テープから適当な大きさのテープを7枚切り取って、それぞれに5点仮ハンダをしておきます。 ![キャプションを入力できます](https://camo.elchika.com/bb01809142f9ab83231272a6dc60216d384b006d/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66343730653066372d383665622d346265662d626539622d393964663263666532323032/) 右から4つずつスイッチの銅線を写真のように接続して、SPRESENSEに接続します。 ![キャプションを入力できます](https://camo.elchika.com/77f4490aaa88c9439643851bd30bf4f2bb8c0b71/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61343032396432642d363463352d346365332d383234362d643732343934633935383533/) ![キャプションを入力できます](https://camo.elchika.com/47787d395de9860b4b58adc16cada638f9306ba5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66666635346562332d316362312d343133342d616336612d616430633834323431663761/) 全部終えると写真のようになります。 ![キャプションを入力できます](https://camo.elchika.com/06aabf9873e6335ed40e3a9aef7477c9db4637e6/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f65383564363032332d373962342d346265392d616566362d613030333232653731396235/) 土台の上に、中面を乗せます。 ![キャプションを入力できます](https://camo.elchika.com/68091585067d8b7f56c32bf748c551ec5161015e/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66646431363932392d656135302d346666392d396566642d646662633333643334346538/) 同様にスイッチと鍵盤を乗せ、各スイッチの2本の銅線を74HC138に接続します。 ![キャプションを入力できます](https://camo.elchika.com/bd418cd75d4ecd14419376e82f3d396da79752f5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f39396530613562642d336562642d343437632d393533642d613133666436336362633536/) 適当な大きさの銅箔テープを7枚切り取り、仮ハンダをしておきます。 ![キャプションを入力できます](https://camo.elchika.com/1da3d21b1ac5476cafdd1c562291e53b2e135c66/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33323738323661632d616634632d346665352d386130662d646366366532303036353138/) ![キャプションを入力できます](https://camo.elchika.com/8213250eea1a38df0c92af60aa250d51ff13ce31/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f61313538363437642d353537332d343264392d626435322d393264313332313464656431/) 右からスイッチを4つずつ接続して、SPRESENSEにつなげます。 ![キャプションを入力できます](https://camo.elchika.com/e965df386d5df91ec9bc1d80148ab446498a227f/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66383734613833652d643162642d343265302d613338392d616130646662343334666433/) 全て繋げたら、写真のようになります。 ![キャプションを入力できます](https://camo.elchika.com/5f2f2e17bbc9d288808844bd87730b72940c0f68/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f38636362376264632d323166652d346539632d383434322d393635663161643831366236/) 上面を乗せます。 ![キャプションを入力できます](https://camo.elchika.com/3dae53f759335467b2d0d1af027f7fffd6f920d0/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f38646338623431332d663239332d343430372d383266322d306636306333626161313638/) **コントロールスイッチ**を作ります。 8個タクトスイッチが乗せられる大きさの基盤を用意します。 今回は白い紙を貼っておきます(任意)。 ![キャプションを入力できます](https://camo.elchika.com/0889fc164e3327e0331d9db8d4d5e5538c6fd84c/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f63373165326265622d303161302d343961652d386239632d336563643932363162343039/) ![キャプションを入力できます](https://camo.elchika.com/b85f810cc83609c83f17784b88aa26edaf46f4ec/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f33356136386430342d613261642d343936622d386536352d363061386231313839333335/) 裏面にハンダ付けします。 ![キャプションを入力できます](https://camo.elchika.com/73ff59274bc98cc39893c00361a5f8ac9a2f2aeb/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35373638373631632d313466612d343333652d386234332d643032353566346262646362/) 銅線を接続します。 ![キャプションを入力できます](https://camo.elchika.com/b8ab2129b80a6c334c72d61f5a50d33edbfb9ea3/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f66396665346139312d303738392d343234612d383031652d396663613739396661303665/) コントロールスイッチの上から出てる8本の線を74HC138に接続し、 左から出てる線をSPRESENSEにつなぎます。 ![キャプションを入力できます](https://camo.elchika.com/5659d33774f7faaaac800a9c604e66a6dd2333fa/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f35393230663662342d363939352d343430392d616434652d633238303039656130653438/) **完成!!!** # デコ例 あとは、お好きなようにデコレーションして、愛着の深まるようなオリジナルなピアノに仕上げましょう。 今回は、**ダイソーさんの千代紙**を鍵盤部に貼って仕上げます。 下の鍵盤は3和音の時のルートノートが割り当てられる鍵盤に千代紙を貼り、 上の鍵盤は4和音以上の時のルートノートが割り当てられる鍵盤に千代紙を貼ってあります。 適当に押しても伴奏になるこのピアノですが、特定の音をピンポイントで出したい時もこのルートノートの鍵盤を目印にすれば、弾きやすくなります。 サードノートを押したい時はルートの鍵盤の右隣を、セブンスノートを出したいときはルートの鍵盤の左隣を押す、といった具合に目印に使えます。 ご参考まで。 ![キャプションを入力できます](https://camo.elchika.com/ffc64a41269f91a30feb203f07a5e391768aeccb/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f30333432646436322d626662382d343739372d626261322d3036383538306262343239622f32663562356436332d643536302d343737362d396331622d363134303363663766633238/) 以下にソースコード(C++)を掲載致します。 著作権への配慮のため、タイトル、歌手名、念のためコード進行などは省いております。 # ソースコード ```spresense:誰でも作れて、誰でも弾けて、誰でもデコれるピアノ #define NUMBER_OF_KEYS 60 #define NUMBER_OF_SWITCHES_FOR_KEYS 120 #define NUMBER_OF_SWITCHES_FOR_CONTROLER 8 #define NUMBER_OF_ALL_SWITCHES 128 #define MAX_MIDI_NOTE 127 #define MAX_MIDI_VELOCITY 120 #define NOTE_VELOCITY 100 #define ARPEGGIO_VELOCITY 100 #define DRUM_VELOCITY 100 #define DRUM_NOTE_NUMBER 36 #define DRUM_MIDI_CHANNEL 10 #define BUTTON_RELEASE_WAIT_TIMES 10 #define USE_LED #define LED 13 #define NUM_LEDS 3 #define BRIGHTNESS 255 #define DATA_PIN PIN_D07 #define LED_FOR_SOUND_HOLE 2 #define LED_FOR_RIGHT_PAD 1 #define LED_FOR_LEFT_PAD 0 #define MIN_INTERVAL_FOR_PART_VOICING 36 #define MAX_INTERVAL_FOR_PART_VOICING 41 #define MIN_INTERVAL_FOR_ALL_VOICING 42 #define MAX_INTERVAL_FOR_ALL_VOICING 47 #define ONE_OCTAVE 12 #define MAX_SIMULTANEOUS_TONES 64 #define HOW_MANY_SONGS 80 #define KEY_UP 1 // #define KEY_DOWN 0 // #define TENSION_F9TH 1 #define TENSION_N9TH 2 #define TENSION_S9TH 3 #define TENSION_N11TH 5 #define TENSION_S11TH 6 #define TENSION_F13TH 8 #define TENSION_N13TH 9 #define TENSION_F14TH 10 #define TYPE_A 1 #define TYPE_B 0 #define RCT 0 #define RCTCTCT 1 #define RIIIV_R_OR_VII 2 enum DIYKeyID : unsigned char { //0~4 DIY_KEY_LS3, DIY_KEY_LS2, DIY_KEY_LS1, DIY_KEY_RS3, DIY_KEY_RS2, //5~31 DIY_KEY_L1, DIY_KEY_L2, DIY_KEY_L3, DIY_KEY_L4, DIY_KEY_L5, DIY_KEY_L6, DIY_KEY_L7, DIY_KEY_L8, DIY_KEY_L9, DIY_KEY_L10, DIY_KEY_L11, DIY_KEY_L12, DIY_KEY_L13, DIY_KEY_L14, DIY_KEY_L15, DIY_KEY_L16, DIY_KEY_L17, DIY_KEY_L18, DIY_KEY_L19, DIY_KEY_L20, DIY_KEY_L21, DIY_KEY_L22, DIY_KEY_L23, DIY_KEY_L24, DIY_KEY_L25, DIY_KEY_L26, DIY_KEY_L27, //32 DIY_KEY_RS1, //33~59 DIY_KEY_R1, DIY_KEY_R2, DIY_KEY_R3, DIY_KEY_R4, DIY_KEY_R5, DIY_KEY_R6, DIY_KEY_R7, DIY_KEY_R8, DIY_KEY_R9, DIY_KEY_R10, DIY_KEY_R11, DIY_KEY_R12, DIY_KEY_R13, DIY_KEY_R14, DIY_KEY_R15, DIY_KEY_R16, DIY_KEY_R17, DIY_KEY_R18, DIY_KEY_R19, DIY_KEY_R20, DIY_KEY_R21, DIY_KEY_R22, DIY_KEY_R23, DIY_KEY_R24, DIY_KEY_R25, DIY_KEY_R26, DIY_KEY_R27, DIY_KEY_DEFAULT = 0xFF, }; enum KeyID : unsigned char { KEY1_36 = 36, KEY1_37, KEY1_38, KEY1_39, KEY1_40, KEY1_41, KEY1_42, KEY1_43, KEY1_44, KEY1_45, KEY1_46, KEY1_47, KEY1_48, KEY1_49, KEY1_50, KEY1_51, KEY1_52, KEY1_53, KEY1_54, KEY1_55, KEY1_56, KEY1_57, KEY1_58, KEY1_59, KEY1_60, KEY1_61, KEY1_62, KEY1_63, KEY1_64, KEY1_65, KEY1_66, KEY1_67, KEY1_68, KEY1_69, KEY1_70, KEY1_71, KEY1_72, KEY1_73, KEY1_74, KEY1_75, KEY1_76, KEY1_77, KEY1_78, KEY1_79, KEY1_80, KEY1_81, KEY1_82, KEY1_83, KEY1_84, KEY1_85, KEY1_86, KEY1_87, KEY1_88, KEY1_89, KEY1_90, KEY1_91, KEY1_92, KEY1_93, KEY1_94, KEY1_95, KEY1_96, KEY2_36, KEY2_37, KEY2_38, KEY2_39, KEY2_40, KEY2_41, KEY2_42, KEY2_43, KEY2_44, KEY2_45, KEY2_46, KEY2_47, KEY2_48, KEY2_49, KEY2_50, KEY2_51, KEY2_52, KEY2_53, KEY2_54, KEY2_55, KEY2_56, KEY2_57, KEY2_58, KEY2_59, KEY2_60, KEY2_61, KEY2_62, KEY2_63, KEY2_64, KEY2_65, KEY2_66, KEY2_67, KEY2_68, KEY2_69, KEY2_70, KEY2_71, KEY2_72, KEY2_73, KEY2_74, KEY2_75, KEY2_76, KEY2_77, KEY2_78, KEY2_79, KEY2_80, KEY2_81, KEY2_82, KEY2_83, KEY2_84, KEY2_85, KEY2_86, KEY2_87, KEY2_88, KEY2_89, KEY2_90, KEY2_91, KEY2_92, KEY2_93, KEY2_94, KEY2_95, KEY2_96,//157 }; enum MidiCH : byte { MIDICH1, MIDICH2, MIDICH3, MIDICH4, MIDICH5, MIDICH6, MIDICH7, MIDICH8, MIDICH9, MIDICH10, MIDICH11, MIDICH12, MIDICH13, MIDICH14, MIDICH15, MIDICH16, }; #define KEY_A KEY1_36 // #define KEY_B KEY1_37 // #define KEY_C KEY1_38 // #define KEY_D KEY1_39 // #define KEY_E KEY1_40 // #define KEY_F KEY1_41 // #define KEY_G KEY1_42 // #define KEY_H KEY1_43 // #define KEY_I KEY1_44 // #define KEY_J KEY1_45 // #define KEY_K KEY1_46 // #define KEY_L KEY1_47 // #define KEY_L_V1 KEY1_91 // #define KEY_L_V2 KEY1_93 // #define KEY_L_V3 KEY1_95 // #define KEY_L_V4 KEY1_96 // #define KEY_R_V1 KEY2_91 // #define KEY_R_V2 KEY2_93 // #define KEY_R_V3 KEY2_95 // #define KEY_R_V4 KEY2_96 // #define KEY_0 KEY1_50 #define KEY_0_ER KEY1_52 #define KEY_0_EST KEY1_53 //#define KEY_LOWEST_ROOT KEY1_53 #define KEY_1_D KEY1_55 #define KEY_1 KEY1_57 #define KEY_1_U KEY1_59 #define KEY_2 KEY1_48 #define KEY_2_ER KEY1_49 #define KEY_2_EST KEY1_51 #define KEY_3_D KEY1_54 #define KEY_3 KEY1_56 #define KEY_3_U KEY1_58 //#define KEY_2 KEY1_71 //#define KEY_3 KEY1_72 #define KEY_4 KEY1_74 #define KEY_5 KEY1_76 #define KEY_6 KEY1_77 #define KEY_7 KEY1_73 #define KEY_L8 KEY1_60 #define KEY_LT2 170 #define KEY_L9 KEY1_62 #define KEY_LB2 171 #define KEY_L10 KEY1_64 #define KEY_L11 KEY1_65 #define KEY_LB3 KEY1_66 #define KEY_L12 KEY1_67 #define KEY_LT3 172 #define KEY_L13 KEY1_69 #define KEY_L14 KEY1_71 #define KEY_L15 KEY1_72 #define KEY_L16 KEY1_74 #define KEY_LT4 173 #define KEY_L17 KEY1_76 #define KEY_L18 KEY1_77 #define KEY_L19 KEY1_79 #define KEY_L20 KEY1_81 #define KEY_LT5 174 #define KEY_L21 KEY1_83 #define KEY_L22 KEY1_84 #define KEY_L23 KEY1_86 #define KEY_L24 KEY1_88 #define KEY_L25 KEY1_89 #define KEY_LT6 175 #define KEY_L26 KEY1_91 #define KEY_L27 KEY1_93 #define KEY_L28 KEY1_95 #define KEY_L29 KEY1_96 #define KEY_R1 KEY2_48 #define KEY_RTLT KEY2_49 #define KEY_R2 KEY2_50 #define KEY_R3 KEY2_52 #define KEY_R4 KEY2_53 #define KEY_R5 KEY2_55 #define KEY_R8 176 #define KEY_RT2 177 #define KEY_R9 178 #define KEY_R10 179 #define KEY_R11 180 #define KEY_R12 KEY1_61 #define KEY_RT3 181 #define KEY_R13 KEY1_63 #define KEY_R14 KEY1_66 #define KEY_R15 KEY1_68 #define KEY_R16 KEY1_70 #define KEY_RT4 182 #define KEY_R17 KEY1_73 #define KEY_R18 KEY1_75 #define KEY_R19 KEY1_78 #define KEY_R20 KEY1_80 #define KEY_RT5 183 #define KEY_R21 KEY1_82 #define KEY_R22 KEY1_85 #define KEY_R23 KEY1_87 #define KEY_R24 KEY1_90 #define KEY_R25 KEY1_92 #define KEY_RT6 184 #define KEY_R26 KEY1_94 #define KEY_R27 185 #define KEY_R28 186 #define KEY_R29 187 #define KEY_EXP_R1_2 DIY_KEY_R1 #define KEY_EXP_R1_1 DIY_KEY_R2 #define KEY_EXP_R1 DIY_KEY_R4 #define KEY_EXP_R2 DIY_KEY_R5 #define KEY_EXP_R3 DIY_KEY_R6 #define KEY_EXP_R4 DIY_KEY_R7 #define KEY_EXP_R5 DIY_KEY_R8 #define KEY_EXP_R6 DIY_KEY_R10 #define KEY_EXP_R7 DIY_KEY_R11 #define KEY_EXP_R8 DIY_KEY_R12 #define KEY_EXP_R9 DIY_KEY_R13 #define KEY_EXP_R10 DIY_KEY_R15 #define KEY_EXP_R11 DIY_KEY_R16 #define KEY_EXP_R12 DIY_KEY_R17 #define KEY_EXP_R13 DIY_KEY_R18 #define KEY_EXP_R14 DIY_KEY_R20 #define KEY_EXP_R15 DIY_KEY_R21 #define KEY_EXP_R16 DIY_KEY_R22 #define KEY_EXP_R17 DIY_KEY_R23 #define KEY_EXP_R18 DIY_KEY_R25 #define KEY_EXP_R19 DIY_KEY_R26 #define KEY_EXP_R20 DIY_KEY_R27 #define KEY_EXP_RU1 DIY_KEY_R3 #define KEY_EXP_RU2 DIY_KEY_R9 #define KEY_EXP_RU3 DIY_KEY_R14 #define KEY_EXP_RU4 DIY_KEY_R19 #define KEY_EXP_RU5 DIY_KEY_R24 #define KEY_EXP_RU6 KEY2_85 #define KEY_EXP_L1_2 DIY_KEY_L1 #define KEY_EXP_L1_1 DIY_KEY_L2 #define KEY_EXP_L1 DIY_KEY_L4 #define KEY_EXP_L2 DIY_KEY_L5 #define KEY_EXP_LB KEY1_58 #define KEY_EXP_L3 DIY_KEY_L6 #define KEY_EXP_L4 DIY_KEY_L7 #define KEY_EXP_L5 DIY_KEY_L8 #define KEY_EXP_L6 DIY_KEY_L10 #define KEY_EXP_L7 DIY_KEY_L11 #define KEY_EXP_L8 DIY_KEY_L12 #define KEY_EXP_L9 DIY_KEY_L13 #define KEY_EXP_L10 DIY_KEY_L15 #define KEY_EXP_L11 DIY_KEY_L16 #define KEY_EXP_L12 DIY_KEY_L17 #define KEY_EXP_L13 DIY_KEY_L18 #define KEY_EXP_L14 DIY_KEY_L20 #define KEY_EXP_L15 DIY_KEY_L21 #define KEY_EXP_L16 DIY_KEY_L22 #define KEY_EXP_L17 DIY_KEY_L23 #define KEY_EXP_L18 DIY_KEY_L25 #define KEY_EXP_L19 DIY_KEY_L26 #define KEY_EXP_L20 DIY_KEY_L27 #define KEY_EXP_LU1 DIY_KEY_L3 #define KEY_EXP_LU2 DIY_KEY_L9 #define KEY_EXP_LU3 DIY_KEY_L14 #define KEY_EXP_LU4 DIY_KEY_L19 #define KEY_EXP_LU5 DIY_KEY_L24 #define KEY_EXP_LU6 KEY1_85 #define THREE_NOTES_CHORD 3 // #define FOUR_NOTES_CHORD 4 // #define FIVE_NOTES_CHORD 5 // #define SIX_NOTES_CHORD 6 // #define SEVEN_NOTES_CHORD 7 // #define SEMITONE_DOWN_1 -1 // #define SEMITONE_DOWN_2 -2 // #define SEMITONE_UP_1 1 // #define SEMITONE_UP_2 2 // #define INTRO 0 #define VER 1 #define PRE 2 #define CHO 3 #define INTER 4 #define BRI 5 #define OUT 6 #define C 1 #define CS 2 #define DF 2 #define D 3 #define DS 4 #define EF 4 #define E 5 #define F 6 #define FS 7 #define GF 7 #define G 8 #define GS 9 #define AF 9 #define A 10 #define AS 11 #define BF 11 #define B 12 #define M 1 #define mi 2 #define SUS4 3 #define DIM 4 #define AUG 5 #define F5 6 #define M7 7 #define N7 8 #define m7 9 #define ADD9 10 #define mADD9 11 #define mM7 12 #define m7SUS4 13 #define N7SUS4 14 #define N7F5 15 #define m7F5 16 #define N7S5 17 #define DIM7 18 #define AUG7 19 #define AUGM7 20 #define N6 21 #define m6 22 #define ADD2 23 #define ADD4 24 #define M9 25 #define N9 26 #define m9 27 #define N7F9 28 #define N7S9 29 #define N7S11 30 #define m7N11 31 #define N7N13 32 #define N9F5 33 #define AUG7F9 34 #define AUG9 35 #define N69 36 #define m69 37 #define N11 38 #define m11 39 #define N13 40 #define m13 41 #define BASE_NOTE 35 //#define BASE_NOTE 47 //#define BASE_NOTE 59 //#define BASE_NOTE 71 #define X 128 #define SSEND 1000 #define RMEND 128 const char title[HOW_MANY_SONGS][60]={}; const byte chord_list[HOW_MANY_SONGS][100][3]={}; const byte chord_progression_array[HOW_MANY_SONGS][300]={}; const int song_structure[HOW_MANY_SONGS][100]{}; const byte riff_melody[HOW_MANY_SONGS][30]{}; class HC138Decoder { protected: // SPRESENSE GPIO 14..16 connected to 74HC138 decoder input volatile uint8_t *modePinA = portModeRegister(digitalPinToPort(PIN_D14)); volatile uint8_t *modePinB = portModeRegister(digitalPinToPort(PIN_D15)); volatile uint8_t *modePinC = portModeRegister(digitalPinToPort(PIN_D16)); volatile uint8_t *portPinA = portOutputRegister(digitalPinToPort(PIN_D14)); volatile uint8_t *portPinB = portOutputRegister(digitalPinToPort(PIN_D15)); volatile uint8_t *portPinC = portOutputRegister(digitalPinToPort(PIN_D16)); //DEMUX control pins static const uint32_t DEMUX_MASK = 0b00000000000000000000000000011100; static const uint32_t DEMUX_STEP = 0b00000000000000000000000000000100; uint32_t demuxChannel[8][3] = { {0, 0, 0}, //channel 0 {1, 0, 0}, //channel 1 {0, 1, 0}, //channel 2 {1, 1, 0}, //channel 3 {0, 0, 1}, //channel 4 {1, 0, 1}, //channel 5 {0, 1, 1}, //channel 6 {1, 1, 1}, //channel 7 }; uint8_t pin[3] = {0,0,0}; // Bit status after sendOut() uint8_t output; // Decoded output (/Y7 .. /Y0, LOW active == bit 1) uint8_t input; // Decoder binary input 0b000..0b111 (0..7) void reset() { input = 0; output = 1; } public: HC138Decoder() { reset(); } void setup() { // Set SPRESENSE pins OUTPUT for 74HC138 input //gpio_set_dir_masked(DEMUX_MASK, DEMUX_MASK); //pinMode( PIN_D14, OUTPUT); pinMode( PIN_D15, OUTPUT); pinMode( PIN_D16, OUTPUT); *modePinA = 0; *modePinB = 0; *modePinC = 0;/* Output setting */ //digitalWrite( PIN_D14, LOW ); digitalWrite( PIN_D15, LOW ); digitalWrite( PIN_D16, LOW ); *portPinA = 0; *portPinB = 0; *portPinC = 0;/* Low */ //gpio_put_masked(DEMUX_MASK, DEMUX_MASK); /*uint8_t n = 0; for(uint32_t mask = 1, i = 0; mask < DEMUX_MASK; mask <<= 1, i++){ if( ( DEMUX_MASK & mask ) == mask ){ pin[n] = i; n++; } }*/ } void next() { if ( (output <<= 1) == 0 ) reset(); else input++; for (uint32_t i = 0; i < 3; i ++) { if(demuxChannel[input][i]) { if(i==0) { *portPinA = 1; } else if(i==1) { *portPinB = 1; } else if(i==2) { *portPinC = 1; } }else{ if(i==0) { *portPinA = 0; } else if(i==1) { *portPinB = 0; } else if(i==2) { *portPinC = 0; } } }//*/ } uint8_t getOutput() { return output; } uint8_t getInput() { return input; } };//*/ enum ButtonID : uint8_t { //0~9 KEY_LS3_A, KEY_LS3_B, KEY_LS2_A, KEY_LS2_B, KEY_LS1_A, KEY_LS1_B, KEY_RS3_A, KEY_RS3_B, KEY_RS2_A, KEY_RS2_B, //10~63 KEY_L1_A, KEY_L1_B, KEY_L2_A, KEY_L2_B, KEY_L3_A, KEY_L3_B, KEY_L4_A, KEY_L4_B, KEY_L5_A, KEY_L5_B, KEY_L6_A, KEY_L6_B, KEY_L7_A, KEY_L7_B, KEY_L8_A, KEY_L8_B, KEY_L9_A, KEY_L9_B, KEY_L10_A, KEY_L10_B, KEY_L11_A, KEY_L11_B, KEY_L12_A, KEY_L12_B, KEY_L13_A, KEY_L13_B, KEY_L14_A, KEY_L14_B, KEY_L15_A, KEY_L15_B, KEY_L16_A, KEY_L16_B, KEY_L17_A, KEY_L17_B, KEY_L18_A, KEY_L18_B, KEY_L19_A, KEY_L19_B, KEY_L20_A, KEY_L20_B, KEY_L21_A, KEY_L21_B, KEY_L22_A, KEY_L22_B, KEY_L23_A, KEY_L23_B, KEY_L24_A, KEY_L24_B, KEY_L25_A, KEY_L25_B, KEY_L26_A, KEY_L26_B, KEY_L27_A, KEY_L27_B, //64、65 KEY_RS1_A, KEY_RS1_B, //66~119 KEY_R1_A, KEY_R1_B, KEY_R2_A, KEY_R2_B, KEY_R3_A, KEY_R3_B, KEY_R4_A, KEY_R4_B, KEY_R5_A, KEY_R5_B, KEY_R6_A, KEY_R6_B, KEY_R7_A, KEY_R7_B, KEY_R8_A, KEY_R8_B, KEY_R9_A, KEY_R9_B, KEY_R10_A, KEY_R10_B, KEY_R11_A, KEY_R11_B, KEY_R12_A, KEY_R12_B, KEY_R13_A, KEY_R13_B, KEY_R14_A, KEY_R14_B, KEY_R15_A, KEY_R15_B, KEY_R16_A, KEY_R16_B, KEY_R17_A, KEY_R17_B, KEY_R18_A, KEY_R18_B, KEY_R19_A, KEY_R19_B, KEY_R20_A, KEY_R20_B, KEY_R21_A, KEY_R21_B, KEY_R22_A, KEY_R22_B, KEY_R23_A, KEY_R23_B, KEY_R24_A, KEY_R24_B, KEY_R25_A, KEY_R25_B, KEY_R26_A, KEY_R26_B, KEY_R27_A, KEY_R27_B, //120~128 DECREMENT_BUTTON, CHANGE_CHORDCHANGINGMODE, CHANGE_INDEX, CHANGE_KEY, CHANGE_SONG_STRUCTURE_INDEX, CHANGE_TRACK, CHANGE_KEYLAYOUT, CHANGE_PLUS_MODE }; class ButtonHandler { public: virtual void handlePressedSwitches( ButtonID button_id, bool calculation_type ); virtual void handleReleasedSwitches( ButtonID button_id, bool calculation_type ); virtual void pressed(ButtonID button_id); virtual void released(ButtonID button_id); }; class ButtonInput { protected: static const uint32_t THIRTY_TWO_BIT_FULL = 0b11111111111111111111111111111111; // SPRESENSE static const uint32_t MASK_START = 0b00000000000000000000000000000001; // SPRESENSE static const uint32_t MASK_FINISH = 0b00000000000000001111111111111111; // SPRESENSE static const uint32_t MASK_A = 0b11111111111111111111111111111110; // SPRESENSE static const uint32_t MASK_B = 0b11111111111111111111111111111101; // SPRESENSE static const uint32_t MASK_C = 0b11111111111111111111111111111011; // SPRESENSE static const uint32_t MASK_D = 0b11111111111111111111111111110111; // SPRESENSE static const uint32_t MASK_E = 0b11111111111111111111111111101111; // SPRESENSE static const uint32_t MASK_F = 0b11111111111111111111111111011111; // SPRESENSE static const uint32_t MASK_G = 0b11111111111111111111111110111111; // SPRESENSE static const uint32_t MASK_H = 0b11111111111111111111111101111111; // SPRESENSE static const uint32_t MASK_I = 0b11111111111111111111111011111111; // SPRESENSE static const uint32_t MASK_J = 0b11111111111111111111110111111111; // SPRESENSE static const uint32_t MASK_K = 0b11111111111111111111101111111111; // SPRESENSE static const uint32_t MASK_L = 0b11111111111111111111011111111111; // SPRESENSE static const uint32_t MASK_M = 0b11111111111111111110111111111111; // SPRESENSE static const uint32_t MASK_N = 0b11111111111111111101111111111111; // SPRESENSE static const uint32_t MASK_O = 0b11111111111111111011111111111111; // SPRESENSE static const uint32_t MASK_P = 0b11111111111111110111111111111111; // SPRESENSE volatile uint8_t *portInputPinA = portInputRegister(digitalPinToPort(PIN_D17)); volatile uint8_t *portInputPinB = portInputRegister(digitalPinToPort(PIN_D18)); volatile uint8_t *portInputPinC = portInputRegister(digitalPinToPort(PIN_D19)); volatile uint8_t *portInputPinD = portInputRegister(digitalPinToPort(PIN_D20)); volatile uint8_t *portInputPinE = portInputRegister(digitalPinToPort(PIN_D21)); volatile uint8_t *portInputPinF = portInputRegister(digitalPinToPort(PIN_D22)); volatile uint8_t *portInputPinG = portInputRegister(digitalPinToPort(PIN_D23)); volatile uint8_t *portInputPinH = portInputRegister(digitalPinToPort(PIN_D24)); volatile uint8_t *portInputPinI = portInputRegister(digitalPinToPort(PIN_D25)); volatile uint8_t *portInputPinJ = portInputRegister(digitalPinToPort(PIN_D26)); volatile uint8_t *portInputPinK = portInputRegister(digitalPinToPort(PIN_D08)); volatile uint8_t *portInputPinL = portInputRegister(digitalPinToPort(PIN_D09)); volatile uint8_t *portInputPinM = portInputRegister(digitalPinToPort(PIN_D10)); volatile uint8_t *portInputPinN = portInputRegister(digitalPinToPort(PIN_D11)); volatile uint8_t *portInputPinO = portInputRegister(digitalPinToPort(PIN_D12)); volatile uint8_t *portInputPinP = portInputRegister(digitalPinToPort(PIN_D13)); uint32_t waiting_after_off[128]; uint32_t input_status[8]; public: boolean isOn(ButtonID bid) { return waiting_after_off[(uint8_t)bid]; } ButtonInput() { memset(waiting_after_off, 0, sizeof(waiting_after_off)); memset(input_status, 0xFFFFFFFF, sizeof(input_status)); } void setup() { pinMode( PIN_D17, INPUT_PULLUP); pinMode( PIN_D18, INPUT_PULLUP); pinMode( PIN_D19, INPUT_PULLUP); pinMode( PIN_D20, INPUT_PULLUP); pinMode( PIN_D21, INPUT_PULLUP); pinMode( PIN_D22, INPUT_PULLUP); pinMode( PIN_D23, INPUT_PULLUP); pinMode( PIN_D24, INPUT_PULLUP); pinMode( PIN_D25, INPUT_PULLUP); pinMode( PIN_D26, INPUT_PULLUP); pinMode( PIN_D08, INPUT_PULLUP); pinMode( PIN_D09, INPUT_PULLUP); pinMode( PIN_D10, INPUT_PULLUP); pinMode( PIN_D11, INPUT_PULLUP); pinMode( PIN_D12, INPUT_PULLUP); pinMode( PIN_D13, INPUT_PULLUP); } void scan(ButtonHandler *handler, HC138Decoder *decoder) { uint8_t new_inputA = *portInputPinA; uint8_t new_inputB = *portInputPinB; uint8_t new_inputC = *portInputPinC; uint8_t new_inputD = *portInputPinD; uint8_t new_inputE = *portInputPinE; uint8_t new_inputF = *portInputPinF; uint8_t new_inputG = *portInputPinG; uint8_t new_inputH = *portInputPinH; uint8_t new_inputI = *portInputPinI; uint8_t new_inputJ = *portInputPinJ; uint8_t new_inputK = *portInputPinK; uint8_t new_inputL = *portInputPinL; uint8_t new_inputM = *portInputPinM; uint8_t new_inputN = *portInputPinN; uint8_t new_inputO = *portInputPinO; uint8_t new_inputP = *portInputPinP; uint32_t new_new_input = THIRTY_TWO_BIT_FULL; if( new_inputA == 0){ new_new_input = new_new_input & MASK_A ; } if( new_inputB == 0){ new_new_input = new_new_input & MASK_B ; } if( new_inputC == 0){ new_new_input = new_new_input & MASK_C ; } if( new_inputD == 0){ new_new_input = new_new_input & MASK_D ; } if( new_inputE == 0){ new_new_input = new_new_input & MASK_E ; } if( new_inputF == 0){ new_new_input = new_new_input & MASK_F ; } if( new_inputG == 0){ new_new_input = new_new_input & MASK_G ; } if( new_inputH == 0){ new_new_input = new_new_input & MASK_H ; } if( new_inputI == 0){ new_new_input = new_new_input & MASK_I ; } if( new_inputJ == 0){ new_new_input = new_new_input & MASK_J ; } if( new_inputK == 0){ new_new_input = new_new_input & MASK_K ; } if( new_inputL == 0){ new_new_input = new_new_input & MASK_L ; } if( new_inputM == 0){ new_new_input = new_new_input & MASK_M ; } if( new_inputN == 0){ new_new_input = new_new_input & MASK_N ; } if( new_inputO == 0){ new_new_input = new_new_input & MASK_O ; } if( new_inputP == 0){ new_new_input = new_new_input & MASK_P ; } //Serial.print( "new_new_input is " ); Serial.println( new_new_input ); uint32_t index = decoder->getInput();//byte index = loop8bit; uint32_t *input = input_status + index; uint32_t change = *input ^ new_new_input; if( change == 0 ) return; //Serial.print( "new_new_input is " ); Serial.print( new_new_input ); Serial.print( " change is " ); Serial.println( change ); *input = new_new_input; for( uint32_t mask = MASK_START; mask <= MASK_FINISH; mask <<= 1, index += 8 ) { if( (change & mask) == 0 ) continue; uint32_t *waiting = waiting_after_off + index; if( (*input & mask) == 0 ) { //Serial.print("Pressed ");Serial.println(index); handler->pressed((ButtonID)index); *waiting = BUTTON_RELEASE_WAIT_TIMES; continue; } if( *waiting == 0 ) { //Serial.print("Released ");Serial.println(index); handler->released((ButtonID)index); continue; } // Cancel bit, and countdown *input ^= mask; (*waiting)--; }//*/ } };//*/ HC138Decoder decoder; ButtonInput button_input; class ChordProgression { protected: uint32_t index; int8_t song_keys; bool kernTriad; uint32_t index_A; uint32_t index_B; //bool chord_A, chord_B, isIndexMinusOne; bool isL_KeysOn, isR_KeysOn, isIndexMinusOne; bool key_layout; bool chord_changing_mode; //bool isABLast; bool isLRLast; uint8_t track; uint32_t total_number_of_cp; uint8_t song_structure_index; uint8_t total_song_structure_index; bool isPlus; bool isBasicBefore; uint8_t padlayout_three_state; bool isFirstLR; bool isRightLast; bool isChangeSongStructureIndex; bool isChangeIndex; bool isRightZero; uint8_t total_number_of_rm; uint8_t riff_melody_r_d_index; uint8_t riff_melody_d_index; uint8_t riff_melody_index; uint8_t riff_melody_u_index; uint8_t riff_melody_r_u_index; uint8_t keylayout_three_state; public: ChordProgression() { index = index_A = song_keys = kernTriad = key_layout = chord_changing_mode = track = total_number_of_cp = song_structure_index = total_song_structure_index = 0; padlayout_three_state = keylayout_three_state = 0; isRightLast = isChangeSongStructureIndex = isChangeIndex = false; total_number_of_rm = riff_melody_r_d_index = riff_melody_d_index = riff_melody_index = riff_melody_u_index = riff_melody_r_u_index = 0; index_B = isBasicBefore = isFirstLR = 1; isIndexMinusOne = isPlus = false; isL_KeysOn = isR_KeysOn = isLRLast = isRightZero = false;} uint32_t getIndex(){ return index; } int8_t getKey(){ return song_keys; } bool getKernTriad(){ return kernTriad; } uint32_t getIndex_A(){ return index_A; } uint32_t getIndex_B(){ return index_B; } //bool getChord_A(){ return chord_A; } //bool getChord_B(){ return chord_B; } bool getIsL_KeysOn(){ return isL_KeysOn; } bool getIsR_KeysOn(){ return isR_KeysOn; } bool getIsIndexMinusOne(){ return isIndexMinusOne; } bool getKey_Layout(){ return key_layout; } bool getChordChangingMode(){ return chord_changing_mode; } //bool getIsABLast(){ return isABLast; } bool getIsLRLast(){ return isLRLast; } uint8_t getTrack(){ return track; } uint32_t getTotalNumberOfCp(){ return total_number_of_cp; } uint8_t getSongStructureIndex(){ return song_structure_index; } uint8_t getTotalSongStructureIndex(){ return total_song_structure_index; } bool getIsPlus(){ return isPlus; } bool getIsBasicBefore(){ return isBasicBefore; } uint8_t getTotal_Number_Of_Rm(){ return total_number_of_rm; } uint8_t getRiff_Melody_R_D_Index(){ return riff_melody_r_d_index; } uint8_t getRiff_Melody_D_Index(){ return riff_melody_d_index; } uint8_t getRiff_Melody_Index(){ return riff_melody_index; } uint8_t getRiff_Melody_U_Index(){ return riff_melody_u_index; } uint8_t getRiff_Melody_R_U_Index(){ return riff_melody_r_u_index; } uint8_t getPadLayout_Three_State(){ return padlayout_three_state; } bool getIsFirstLR(){ return isFirstLR; } bool getIsRightLast(){ return isRightLast; } bool getIsChangeSongStructureIndex(){ return isChangeSongStructureIndex; } bool getIsChangeIndex(){ return isChangeIndex; } bool getIsRightZero(){ return isRightZero; } uint8_t getKeyLayoutThreeState(){ return keylayout_three_state; } void setIndex(uint32_t num_index){ index = num_index; } void setKey(int8_t num_key){ song_keys = num_key; } void setKernTriad(bool kt){ kernTriad = kt; } void setIndex_A(uint32_t num_index){ index_A = num_index; } void setIndex_B(uint32_t num_index){ index_B = num_index; } //void setChord_A(bool flag){ chord_A = flag; } //void setChord_B(bool flag){ chord_B = flag; } void setIsL_KeysOn(bool ilko){ isL_KeysOn = ilko; } void setIsR_KeysOn(bool orko){ isR_KeysOn = orko; } void setIsIndexMinusOne(bool iimo){ isIndexMinusOne = iimo; } void setKey_Layout(bool kl){ key_layout = kl; } void setChordChangingMode(bool ccm){ chord_changing_mode = ccm; } //void setIsABLast(bool iabl){ isABLast = iabl; } void setIsLRLast(bool ilrl){ isLRLast = ilrl; } void setTrack(uint8_t t){ track = t; } void setSongStructureIndex(uint8_t ssi){ song_structure_index = ssi; } void setIsPlus(bool ip){ isPlus = ip; } void setIsBasicBefore(bool ibb){ isBasicBefore = ibb; } void setTotal_Number_Of_Rm(uint8_t tnor){ total_number_of_rm = tnor; } void setRiff_Melody_R_D_Index(uint8_t rmrdi){ riff_melody_r_d_index = rmrdi; } void setRiff_Melody_D_Index(uint8_t rmdi){ riff_melody_d_index = rmdi; } void setRiff_Melody_Index(uint8_t rmi){ riff_melody_index = rmi; } void setRiff_Melody_U_Index(uint8_t rmui){ riff_melody_u_index = rmui; } void setRiff_Melody_R_U_Index(uint8_t rmrui){ riff_melody_r_u_index = rmrui; } void setPadLayout_Three_State(uint8_t plts){ padlayout_three_state = plts; } void setIsFirstLR(bool iflr){ isFirstLR = iflr; } void setIsRightLast(bool irl){ isRightLast = irl; } void setIsChangeSongStructureIndex(bool icssi){ isChangeSongStructureIndex = icssi; } void setIsChangeIndex(bool ici){ isChangeIndex = ici; } void setIsRightZero(bool irz){ isRightZero = irz; } void setKeyLayoutThreeState(uint8_t klts){ keylayout_three_state = klts; } void track_init(){ track = 0; } void indexInit(){ index = index_A = 0; index_B = 1; isIndexMinusOne = false; isL_KeysOn = isR_KeysOn = isLRLast = false; } void song_init(){ index = 0; isL_KeysOn = isR_KeysOn = isIndexMinusOne = isLRLast = false; index_A = 0; index_B = isBasicBefore = isFirstLR = 1; song_keys = total_number_of_cp = song_structure_index = 0; total_number_of_rm = riff_melody_r_d_index = riff_melody_d_index = riff_melody_index = riff_melody_u_index = riff_melody_r_u_index = 0; isRightLast = isRightZero = isChangeSongStructureIndex = isChangeIndex = false; for(uint32_t i = 0; i < 100; i++){ //if(song_structure[track][i] == SSEND) {total_song_structure_index = i/3; break;} if(song_structure[track][i] == SSEND) {total_song_structure_index = i; break;} } for(uint32_t i = 0; i < 300; i++){ if(chord_progression_array[track][i] == X) {total_number_of_cp = i; break;} } for(uint32_t i = 0; i < 30; i++){ if( riff_melody[ track ][ i ] == RMEND ){ total_number_of_rm = i; break; } } } void compare_index(){ for(uint32_t i = 0; i < total_song_structure_index; i++){ if( index == song_structure[ track ][ i ] ){ song_structure_index = i; break; } } } void compare_index_less_than(){ if( index < song_structure[ track ][ song_structure_index ] ){ if( song_structure_index != 0 ) song_structure_index--; } } }; class PrintIntervalsHandler { protected: public: PrintIntervalsHandler() { } void setup() { } void print_root( int32_t r ){ if( r <= 0 ) r += ONE_OCTAVE; else if( 13 <= r ) r -= ONE_OCTAVE; switch( r ){ case 1 : Serial.print("C"); break; case 2 : Serial.print("C#(D♭)"); break; case 3 : Serial.print("D"); break; case 4 : Serial.print("D#(E♭)"); break; case 5 : Serial.print("E"); break; case 6 : Serial.print("F"); break; case 7 : Serial.print("F#(G♭)"); break; case 8 : Serial.print("G"); break; case 9 : Serial.print("G#(A♭)"); break; case 10 : Serial.print("A"); break; case 11 : Serial.print("A#(B♭)"); break; case 12 : Serial.print("B"); break; } } void print_identifier( uint8_t i ){ switch( i ){ case M : Serial.print("M"); break; case mi : Serial.print("m"); break; case SUS4 : Serial.print("sus4"); break; case DIM : Serial.print("dim"); break; case AUG : Serial.print("aug"); break; case F5 : Serial.print("-5"); break; case M7 : Serial.print("M7"); break; case N7 : Serial.print("7"); break; case m7 : Serial.print("m7"); break; case ADD9 : Serial.print("add9"); break; case mADD9 : Serial.print("madd9"); break; case mM7 : Serial.print("mM7"); break; case N7SUS4 : Serial.print("7sus4"); break; case N7F5 : Serial.print("7-5"); break; case m7F5 : Serial.print("m7-5"); break; case N7S5 : Serial.print("7+5"); break; case DIM7 : Serial.print("dim7"); break; case AUG7 : Serial.print("aug7"); break; case AUGM7 : Serial.print("augM7"); break; case N6 : Serial.print("6"); break; case m6 : Serial.print("m6"); break; case ADD2 : Serial.print("add2"); break; case ADD4 : Serial.print("add4"); break; case M9 : Serial.print("M9"); break; case N9 : Serial.print("9"); break; case m9 : Serial.print("m9"); break; case N7F9 : Serial.print("7(♭9)"); break; case N7S9 : Serial.print("7(#9)"); break; case N7S11 : Serial.print("7(#11)"); break; case m7N11 : Serial.print("m7(11)"); break; case N7N13 : Serial.print("7(13)"); break; case N9F5 : Serial.print("9-5"); break; case AUG7F9 : Serial.print("aug7(♭9)"); break; case AUG9 : Serial.print("aug9"); break; case N69 : Serial.print("69"); break; case m69 : Serial.print("m69"); break; case N11 : Serial.print("11"); break; case m11 : Serial.print("m11"); break; case N13 : Serial.print("13"); break; case m13 : Serial.print("m13"); break; } } void print_compound( uint32_t c ){ switch( c ){ case 0 : Serial.println(""); break; case 1 : Serial.println(" / C"); break; case 2 : Serial.println(" / C#(D♭)"); break; case 3 : Serial.println(" / D"); break; case 4 : Serial.println(" / D#(E♭)"); break; case 5 : Serial.println(" / E"); break; case 6 : Serial.println(" / F"); break; case 7 : Serial.println(" / F#(G♭)"); break; case 8 : Serial.println(" / G"); break; case 9 : Serial.println(" / G#(A♭)"); break; case 10 : Serial.println(" / A"); break; case 11 : Serial.println(" / A#(B♭)"); break; case 12 : Serial.println(" / B"); break; } } void print_compound( int32_t c, int32_t k ){ if( k == 0 ){} else if( 0 < k ){ if( 13 <= c ) c -= ONE_OCTAVE; } else if( k < 0 ){ if( c == 0 ) c = 12; else if( c < 0 ) c += ONE_OCTAVE; } switch( c ){ case 0 : Serial.println(""); break; case 1 : Serial.println(" / C"); break; case 2 : Serial.println(" / C#(D♭)"); break; case 3 : Serial.println(" / D"); break; case 4 : Serial.println(" / D#(E♭)"); break; case 5 : Serial.println(" / E"); break; case 6 : Serial.println(" / F"); break; case 7 : Serial.println(" / F#(G♭)"); break; case 8 : Serial.println(" / G"); break; case 9 : Serial.println(" / G#(A♭)"); break; case 10 : Serial.println(" / A"); break; case 11 : Serial.println(" / A#(B♭)"); break; case 12 : Serial.println(" / B"); break; } } void mod12( uint8_t m ){ Serial.print("音階: "); Serial.print(m); uint8_t the_octave = m/12; uint8_t the_interval = m%12; switch( the_interval ){ case 0 : Serial.print(" / ド / C"); break; case 1 : Serial.print(" / ド#(レ♭) / C#(D♭)"); break; case 2 : Serial.print(" / レ / D"); break; case 3 : Serial.print(" / レ#(ミ♭) / D#(E♭)"); break; case 4 : Serial.print(" / ミ / E"); break; case 5 : Serial.print(" / ファ / F"); break; case 6 : Serial.print(" / ファ#(ソ♭) / F#(G♭)"); break; case 7 : Serial.print(" / ソ / G"); break; case 8 : Serial.print(" / ソ#(ラ♭) / G#(A♭)"); break; case 9 : Serial.print(" / ラ / A"); break; case 10 : Serial.print(" / ラ#(シ♭) / A#(B♭)"); break; case 11 : Serial.print(" / シ / B"); break; } Serial.println( the_octave-1 ); //国際式は-1 //Serial.println(the_octave-2); //ヤマハ式は-2 } };//*/ PrintIntervalsHandler print_intervals; class Interval { protected: uint8_t root_note; uint8_t flat_second_note; uint8_t second_note; uint8_t flat_third_note; uint8_t third_note; uint8_t fourth_note; uint8_t flat_fifth_note; uint8_t fifth_note; uint8_t flat_sixth_note; uint8_t sixth_note; uint8_t flat_seventh_note; uint8_t seventh_note; uint8_t eighth_note; uint8_t flat_ninth_note; uint8_t ninth_note; uint8_t flat_tenth_note; uint8_t tenth_note; uint8_t eleventh_note; uint8_t flat_twelveth_note; uint8_t twelveth_note; uint8_t flat_thirteenth_note; uint8_t thirteenth_note; uint8_t flat_fourteenth_note; uint8_t fourteenth_note; uint8_t b_root_note; uint8_t b_flat_second_note; uint8_t b_second_note; uint8_t b_flat_third_note; uint8_t b_third_note; uint8_t b_fourth_note; uint8_t b_flat_fifth_note; uint8_t b_fifth_note; uint8_t b_flat_sixth_note; uint8_t b_sixth_note; uint8_t b_flat_seventh_note; uint8_t b_seventh_note; uint8_t b_eighth_note; uint8_t b_flat_ninth_note; uint8_t b_ninth_note; uint8_t b_flat_tenth_note; uint8_t b_tenth_note; uint8_t b_eleventh_note; uint8_t b_flat_twelveth_note; uint8_t b_twelveth_note; uint8_t b_flat_thirteenth_note; uint8_t b_thirteenth_note; uint8_t b_flat_fourteenth_note; uint8_t b_fourteenth_note; uint8_t next_root_note; byte b_next_root_note; bool isSemitoneKeysOn; uint8_t semitone_up_down_1; uint8_t semitone_up_down_2; bool flag_next_compound; uint8_t next_compound_diff; bool flag_compound; uint8_t compound_diff; bool is_root_greater_than_compound; bool is_next_root_greater_than_next_compound; uint8_t ichi; uint8_t san; uint8_t go; uint8_t nana; uint8_t keys_on_off[ NUMBER_OF_KEYS ]; uint8_t compounds[5]; uint8_t current_simultaneous_tones; uint8_t assigned_note[ MAX_SIMULTANEOUS_TONES ]; uint8_t four_notes[4] = {}; bool flag_triad; bool flag_five_notes_chord; bool flag_six_notes_chord; bool flag_seven_notes_chord; uint8_t number_of_notes; uint8_t the_lowest_note_index; uint8_t tension_diff; uint8_t walking_bass_root_note; uint8_t walking_bass_next_root_note; uint8_t walking_bass_recent_next; uint8_t walking_bass_note1; uint8_t walking_bass_note2; uint8_t walking_bass_note3; uint8_t walking_bass_note4; uint8_t v1,v2,v3,v4,v5; public: Interval() { root_note = 0; flat_second_note = 0; second_note = 0; flat_third_note = 0; third_note = 0; fourth_note = 0; flat_fifth_note = 0; fifth_note = 0; flat_sixth_note = 0; sixth_note = 0; flat_seventh_note = 0; seventh_note = 0; eighth_note = 0; flat_ninth_note = 0; ninth_note = 0; flat_tenth_note = 0; tenth_note = 0; eleventh_note = 0; flat_twelveth_note = 0; twelveth_note = 0; flat_thirteenth_note = 0; thirteenth_note = 0; flat_fourteenth_note = 0; fourteenth_note = 0; b_root_note = 0; b_flat_second_note = 0; b_second_note = 0; b_flat_third_note = 0; b_third_note = 0; b_fourth_note = 0; b_flat_fifth_note = 0; b_fifth_note = 0; b_flat_sixth_note = 0; b_sixth_note = 0; b_flat_seventh_note = 0; b_seventh_note = 0; b_eighth_note = 0; b_flat_ninth_note = 0; b_ninth_note = 0; b_flat_tenth_note = 0; b_tenth_note = 0; b_eleventh_note = 0; b_flat_twelveth_note = 0; b_twelveth_note = 0; b_flat_thirteenth_note = 0; b_thirteenth_note = 0; b_flat_fourteenth_note = 0; b_fourteenth_note = 0; next_root_note = 0; b_next_root_note = 0; isSemitoneKeysOn = false; semitone_up_down_1 = 0; semitone_up_down_2 = 0; flag_next_compound = false; next_compound_diff = 0; flag_compound = false; compound_diff = 0; is_root_greater_than_compound = false; is_next_root_greater_than_next_compound = false; ichi = san = go = nana = 0; flag_triad = false; flag_five_notes_chord = false; flag_six_notes_chord = false; flag_seven_notes_chord = false; number_of_notes = 0; the_lowest_note_index = 0; tension_diff = 0; walking_bass_root_note = 0; walking_bass_next_root_note = 0; walking_bass_recent_next = 0; walking_bass_note1 = 0; walking_bass_note2 = 0; walking_bass_note3 = 0; walking_bass_note4 = 0; v1 = v2 = v3 = v4 = v5 = 0; memset(keys_on_off, 0, sizeof(keys_on_off)); memset(assigned_note, 0, sizeof(assigned_note)); memset(compounds, 0, sizeof(compounds)); memset(four_notes, 0, sizeof(four_notes)); current_simultaneous_tones = 0; } void swap(uint8_t *interval1, uint8_t *interval2){ uint8_t var = 0; var = *interval1; *interval1 = *interval2; *interval2 = var; } void set_intevals( ChordProgression* cp ){ uint8_t root, identifier, compound, next_root, next_compound = 0; flag_next_compound = false; flag_compound = false; is_root_greater_than_compound = false; is_next_root_greater_than_next_compound = false; flag_triad = false; flag_five_notes_chord = false; flag_six_notes_chord = false; flag_seven_notes_chord = false; number_of_notes = 0; the_lowest_note_index = 0; tension_diff = 0; Serial.print("cp->getIndex() is ");Serial.println(cp->getIndex()); root = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ cp->getIndex() ]][0]; identifier = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ cp->getIndex() ]][1]; compound = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ cp->getIndex() ]][2];//*/ if( cp->getIndex() == ( cp->getTotalNumberOfCp() - 1) ){ next_root = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ 0 ]][0]; next_compound = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ 0 ]][2]; }else{ next_root = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ cp->getIndex()+1 ]][0]; next_compound = chord_list[ cp->getTrack() ][ chord_progression_array[ cp->getTrack() ][ cp->getIndex()+1 ]][2]; } long randNumber = random(2); if( randNumber == 0 ){ semitone_up_down_1 = SEMITONE_DOWN_1; semitone_up_down_2 = SEMITONE_DOWN_2; }else{ semitone_up_down_1 = SEMITONE_UP_1; semitone_up_down_2 = SEMITONE_UP_2; } Serial.print("コードネーム: "); print_intervals.print_root( root ); print_intervals.print_identifier( identifier ); print_intervals.print_compound( compound ); if( cp->getKey() != 0 ){ Serial.print("曲のキーが ");Serial.print(cp->getKey());Serial.print(" の時のコードネーム: "); print_intervals.print_root( root + cp->getKey() ); print_intervals.print_identifier( identifier ); if( compound != 0 ) print_intervals.print_compound( compound + cp->getKey(), cp->getKey() ); else Serial.println(""); } //1st root_note = BASE_NOTE+root; b_root_note = BASE_NOTE+root; next_root_note = BASE_NOTE+next_root; b_next_root_note = BASE_NOTE+next_root; walking_bass_root_note = b_root_note; walking_bass_next_root_note = next_root_note; if(cp->getKey_Layout()){ if(MIN_INTERVAL_FOR_PART_VOICING <= root_note && root_note <= MAX_INTERVAL_FOR_PART_VOICING){ //Flat 2nd flat_second_note = root_note+1; if(MIN_INTERVAL_FOR_ALL_VOICING <= flat_second_note) flat_second_note -= 12; //2nd second_note = root_note+2; if(MIN_INTERVAL_FOR_ALL_VOICING <= second_note) second_note -= 12; //flat 3rd flat_third_note = root_note+3; if(MIN_INTERVAL_FOR_ALL_VOICING <= flat_third_note) flat_third_note -= 12; //3rd third_note = root_note+4; if(MIN_INTERVAL_FOR_ALL_VOICING <= third_note) third_note -= 12; //4th fourth_note = root_note+5; if(MIN_INTERVAL_FOR_ALL_VOICING <= fourth_note) fourth_note -= 12; //flat 5th flat_fifth_note = root_note+6; if(MIN_INTERVAL_FOR_ALL_VOICING <= flat_fifth_note) flat_fifth_note -= 12; //5th fifth_note = root_note+7; if(MIN_INTERVAL_FOR_ALL_VOICING <= fifth_note) fifth_note -= 12; //flat 6th flat_sixth_note = root_note+8; if(MIN_INTERVAL_FOR_ALL_VOICING <= flat_sixth_note) flat_sixth_note -= 12; //6th sixth_note = root_note+9; if(MIN_INTERVAL_FOR_ALL_VOICING <= sixth_note) sixth_note -= 12; //flat 7th flat_seventh_note = root_note+10; if(MIN_INTERVAL_FOR_ALL_VOICING <= flat_seventh_note) flat_seventh_note -= 12; //7th seventh_note = root_note+11; if(MIN_INTERVAL_FOR_ALL_VOICING <= seventh_note) seventh_note -= 12; } else if(MIN_INTERVAL_FOR_ALL_VOICING <= root_note && root_note <= MAX_INTERVAL_FOR_ALL_VOICING) { root_note -= 12; //Flat 2nd flat_second_note = root_note+1; //2nd second_note = root_note+2; //flat 3rd flat_third_note = root_note+3; //3rd third_note = root_note+4; //4th fourth_note = root_note+5; //flat 5th flat_fifth_note = root_note+6; //5th fifth_note = root_note+7; //flat 6th flat_sixth_note = root_note+8; //6th sixth_note = root_note+9; //flat 7th flat_seventh_note = root_note+10; //7th seventh_note = root_note+11; }//*/ //8th eighth_note = root_note+12; //flat 9th flat_ninth_note = flat_second_note+12; //9th ninth_note = second_note+12; //flat 10th flat_tenth_note = flat_third_note+12; //10th tenth_note = third_note+12; //11th eleventh_note = fourth_note+12; //flat 12th flat_twelveth_note = flat_fifth_note+12; //12th twelveth_note = fifth_note+12; //flat 13th flat_thirteenth_note = flat_sixth_note+12; //13th thirteenth_note = sixth_note+12; //flat 14th flat_fourteenth_note = flat_seventh_note+12; //14th fourteenth_note = seventh_note+12; } else{ //Flat 2nd flat_second_note = root_note+1; //2nd second_note = root_note+2; //flat 3rd flat_third_note = root_note+3; //3rd third_note = root_note+4; //4th fourth_note = root_note+5; //flat 5th flat_fifth_note = root_note+6; //5th fifth_note = root_note+7; //flat 6th flat_sixth_note = root_note+8; //6th sixth_note = root_note+9; //flat 7th flat_seventh_note = root_note+10; //7th seventh_note = root_note+11; //8th eighth_note = root_note+12; //flat 9th flat_ninth_note = flat_second_note+12; //9th ninth_note = second_note+12; //flat 10th flat_tenth_note = flat_third_note+12; //10th tenth_note = third_note+12; //11th eleventh_note = fourth_note+12; //flat 12th flat_twelveth_note = flat_fifth_note+12; //12th twelveth_note = fifth_note+12; //flat 13th flat_thirteenth_note = flat_sixth_note+12; //13th thirteenth_note = sixth_note+12; //flat 14th flat_fourteenth_note = flat_seventh_note+12; //14th fourteenth_note = seventh_note+12; } if( cp->getIsPlus() ){ //b_root_note += 12; /*if(MIN_INTERVAL_FOR_ALL_VOICING <= b_root_note && b_root_note <= MAX_INTERVAL_FOR_ALL_VOICING) { b_root_note -= 12; }*/ } //Flat 2nd b_flat_second_note = b_root_note+1; //2nd b_second_note = b_root_note+2; //flat 3rd b_flat_third_note = b_root_note+3; //3rd b_third_note = b_root_note+4; //4th b_fourth_note = b_root_note+5; //flat 5th b_flat_fifth_note = b_root_note+6; //5th b_fifth_note = b_root_note+7; //flat 6th b_flat_sixth_note = b_root_note+8; //6th b_sixth_note = b_root_note+9; //flat 7th b_flat_seventh_note = b_root_note+10; //7th b_seventh_note = b_root_note+11; //8th b_eighth_note = b_root_note+12; //flat 9th b_flat_ninth_note = b_flat_second_note+12; //9th b_ninth_note = b_second_note+12; //flat 10th b_flat_tenth_note = b_flat_third_note+12; //10th b_tenth_note = b_third_note+12; //11th b_eleventh_note = b_fourth_note+12; //flat 12th b_flat_twelveth_note = b_flat_fifth_note+12; //12th b_twelveth_note = b_fifth_note+12; //flat 13th b_flat_thirteenth_note = b_flat_sixth_note+12; //13th b_thirteenth_note = b_sixth_note+12; //flat 14th b_flat_fourteenth_note = b_flat_seventh_note+12; //14th b_fourteenth_note = b_seventh_note+12; if(cp->getKey_Layout()){ if(MIN_INTERVAL_FOR_ALL_VOICING <= next_root_note && next_root_note <= MAX_INTERVAL_FOR_ALL_VOICING) { next_root_note -= 12; } } //1st & compound note if( compound!=0 ){ flag_compound = true; if( compound > root ){ is_root_greater_than_compound = false; compound_diff = 12 - ( compound - root ); } else if( root > compound ){ is_root_greater_than_compound = true; compound_diff = root - compound; } } if( next_compound!=0 ){ flag_next_compound = true; if( next_compound > next_root ){ is_next_root_greater_than_next_compound = false; next_compound_diff = 12 - ( next_compound - next_root ); } else if( next_root > next_compound ){ is_next_root_greater_than_next_compound = true; next_compound_diff = next_root - next_compound; } } //Serial.println( random(0, 100) ); switch(identifier){ case M : tension_diff = TENSION_N9TH; break; case mi : swap(&flat_third_note,&third_note); swap(&flat_tenth_note,&tenth_note); tension_diff = TENSION_F14TH;//10;//TENSION_F14TH;//TENSION_N11TH; break; case SUS4 : swap(&third_note,&fourth_note); swap(&tenth_note,&eleventh_note); tension_diff = TENSION_N13TH; break; case DIM : swap(&flat_third_note,&third_note); swap(&flat_fifth_note,&fifth_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_twelveth_note,&twelveth_note); tension_diff = TENSION_F13TH; break; case AUG : swap(&flat_sixth_note,&fifth_note); swap(&flat_thirteenth_note,&twelveth_note); tension_diff = TENSION_N9TH; break; case F5 : swap(&flat_fifth_note,&fifth_note); swap(&flat_twelveth_note,&twelveth_note); tension_diff = TENSION_N13TH; break; case M7 : tension_diff = TENSION_N9TH; break; case N7 : swap(&flat_seventh_note,&seventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case m7 : swap(&flat_third_note,&third_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N11TH; break; case ADD9 : swap(&ninth_note,&seventh_note); second_note = ninth_note - 12; fourteenth_note = seventh_note + 12; tension_diff = TENSION_N13TH; break; case mADD9 : swap(&flat_third_note,&third_note); swap(&flat_tenth_note,&tenth_note); swap(&ninth_note,&seventh_note); second_note = ninth_note - 12; fourteenth_note = seventh_note + 12; tension_diff = TENSION_N13TH; break; case mM7 : swap(&flat_third_note,&third_note); swap(&flat_tenth_note,&tenth_note); tension_diff = TENSION_N11TH; break; case m7SUS4 : swap(&third_note,&fourth_note); swap(&flat_seventh_note,&seventh_note); swap(&tenth_note,&eleventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case N7SUS4 : swap(&third_note,&fourth_note); swap(&flat_seventh_note,&seventh_note); swap(&tenth_note,&eleventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case N7F5 : swap(&flat_fifth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_twelveth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case m7F5 : swap(&flat_third_note,&third_note); swap(&flat_fifth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_twelveth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_F13TH; break; case N7S5 : swap(&flat_sixth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_thirteenth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case DIM7 : swap(&flat_third_note,&third_note); swap(&flat_fifth_note,&fifth_note); swap(&sixth_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_twelveth_note,&twelveth_note); swap(&thirteenth_note,&fourteenth_note); tension_diff = TENSION_N11TH; break; case AUG7 : swap(&flat_sixth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_thirteenth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case AUGM7 : swap(&flat_sixth_note,&fifth_note); swap(&flat_thirteenth_note,&twelveth_note); tension_diff = TENSION_N9TH; break; case N6 : swap(&sixth_note,&seventh_note); swap(&thirteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case m6 : swap(&flat_third_note,&third_note); swap(&sixth_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&thirteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case ADD2 : swap(&second_note,&seventh_note); swap(&ninth_note,&fourteenth_note); tension_diff = TENSION_N13TH; break; case ADD4 : swap(&fourth_note,&seventh_note); swap(&eleventh_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case M9 : tension_diff = TENSION_N9TH; break; case N9 : swap(&flat_seventh_note,&seventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case m9 : swap(&flat_third_note,&third_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case N7F9 : swap(&flat_seventh_note,&seventh_note); swap(&flat_ninth_note,&ninth_note); swap(&flat_fourteenth_note,&fourteenth_note); swap(&flat_second_note,&second_note); tension_diff = TENSION_F9TH; break; case N7S9 : swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&ninth_note); swap(&flat_fourteenth_note,&fourteenth_note); swap(&flat_third_note,&second_note); tension_diff = TENSION_S9TH; break; case N7S11 : swap(&flat_seventh_note,&seventh_note); swap(&flat_twelveth_note,&eleventh_note); swap(&flat_fourteenth_note,&fourteenth_note); swap(&flat_fifth_note,&fourth_note); tension_diff = TENSION_S11TH; break; case m7N11 : swap(&flat_third_note,&third_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N11TH; break; case N7N13 : swap(&flat_seventh_note,&seventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N13TH; break; case N9F5 : swap(&flat_fifth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_twelveth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case AUG7F9 : swap(&flat_sixth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_ninth_note,&ninth_note); swap(&flat_thirteenth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); swap(&flat_second_note,&second_note); tension_diff = TENSION_F9TH; break; case AUG9 : swap(&flat_sixth_note,&fifth_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_thirteenth_note,&twelveth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case N69 : swap(&sixth_note,&seventh_note); swap(&thirteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case m69 : swap(&flat_third_note,&third_note); swap(&sixth_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&thirteenth_note,&fourteenth_note); tension_diff = TENSION_N9TH; break; case N11 : swap(&flat_seventh_note,&seventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N11TH; break; case m11 : swap(&flat_third_note,&third_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N11TH; break; case N13 : swap(&flat_seventh_note,&seventh_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N13TH; break; case m13 : swap(&flat_third_note,&third_note); swap(&flat_seventh_note,&seventh_note); swap(&flat_tenth_note,&tenth_note); swap(&flat_fourteenth_note,&fourteenth_note); tension_diff = TENSION_N13TH; break; } switch(identifier){ case M : tension_diff = TENSION_N9TH; break; case mi : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_tenth_note,&b_tenth_note); tension_diff = TENSION_F14TH;//10;//TENSION_F14TH;//TENSION_N11TH; break; case SUS4 : swap(&b_third_note,&b_fourth_note); swap(&b_tenth_note,&b_eleventh_note); tension_diff = TENSION_N13TH; break; case DIM : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_fifth_note,&b_fifth_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_twelveth_note,&b_twelveth_note); tension_diff = TENSION_F13TH; break; case AUG : swap(&b_flat_sixth_note,&b_fifth_note); swap(&b_flat_thirteenth_note,&b_twelveth_note); tension_diff = TENSION_N9TH; break; case F5 : swap(&b_flat_fifth_note,&b_fifth_note); swap(&b_flat_twelveth_note,&b_twelveth_note); tension_diff = TENSION_N13TH; break; case M7 : tension_diff = TENSION_N9TH; break; case N7 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case m7 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N11TH; break; case ADD9 : swap(&b_ninth_note,&b_seventh_note); second_note = ninth_note - 12; fourteenth_note = seventh_note + 12; tension_diff = TENSION_N13TH; break; case mADD9 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_ninth_note,&b_seventh_note); b_second_note = b_ninth_note - 12; b_fourteenth_note = b_seventh_note + 12; tension_diff = TENSION_N13TH; break; case mM7 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_tenth_note,&b_tenth_note); tension_diff = TENSION_N11TH; break; case m7SUS4 : swap(&b_third_note,&b_fourth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_tenth_note,&b_eleventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case N7SUS4 : swap(&b_third_note,&b_fourth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_tenth_note,&b_eleventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case N7F5 : swap(&b_flat_fifth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_twelveth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case m7F5 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_fifth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_twelveth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_F13TH; break; case N7S5 : swap(&b_flat_sixth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_thirteenth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case DIM7 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_fifth_note,&b_fifth_note); swap(&b_sixth_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_twelveth_note,&b_twelveth_note); swap(&b_thirteenth_note,&b_fourteenth_note); tension_diff = TENSION_N11TH; break; case AUG7 : swap(&b_flat_sixth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_thirteenth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case AUGM7 : swap(&b_flat_sixth_note,&b_fifth_note); swap(&b_flat_thirteenth_note,&b_twelveth_note); tension_diff = TENSION_N9TH; break; case N6 : swap(&b_sixth_note,&b_seventh_note); swap(&b_thirteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case m6 : swap(&b_flat_third_note,&b_third_note); swap(&b_sixth_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_thirteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case ADD2 : swap(&b_second_note,&b_seventh_note); swap(&b_ninth_note,&b_fourteenth_note); tension_diff = TENSION_N13TH; break; case ADD4 : swap(&b_fourth_note,&b_seventh_note); swap(&b_eleventh_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case M9 : tension_diff = TENSION_N9TH; break; case N9 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case m9 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case N7F9 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_ninth_note,&b_ninth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); swap(&b_flat_second_note,&b_second_note); tension_diff = TENSION_F9TH; break; case N7S9 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_ninth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); swap(&b_flat_third_note,&b_second_note); tension_diff = TENSION_S9TH; break; case N7S11 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_twelveth_note,&b_eleventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); swap(&b_flat_fifth_note,&b_fourth_note); tension_diff = TENSION_S11TH; break; case m7N11 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N11TH; break; case N7N13 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N13TH; break; case N9F5 : swap(&b_flat_fifth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_twelveth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case AUG7F9 : swap(&b_flat_sixth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_ninth_note,&b_ninth_note); swap(&b_flat_thirteenth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); swap(&b_flat_second_note,&b_second_note); tension_diff = TENSION_F9TH; break; case AUG9 : swap(&b_flat_sixth_note,&b_fifth_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_thirteenth_note,&b_twelveth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case N69 : swap(&b_sixth_note,&b_seventh_note); swap(&b_thirteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case m69 : swap(&b_flat_third_note,&b_third_note); swap(&b_sixth_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_thirteenth_note,&b_fourteenth_note); tension_diff = TENSION_N9TH; break; case N11 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N11TH; break; case m11 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N11TH; break; case N13 : swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N13TH; break; case m13 : swap(&b_flat_third_note,&b_third_note); swap(&b_flat_seventh_note,&b_seventh_note); swap(&b_flat_tenth_note,&b_tenth_note); swap(&b_flat_fourteenth_note,&b_fourteenth_note); tension_diff = TENSION_N13TH; break; } if(identifier==M || identifier==mi || identifier==SUS4 || identifier==DIM || identifier==AUG || identifier==F5) { seventh_note = X; fourteenth_note = X; //b_seventh_note = X; b_fourteenth_note = X; flag_triad = true; number_of_notes = 3; } if( identifier==M7 || identifier==N7 || identifier==m7 || identifier==ADD9 || identifier==mADD9 || identifier==mM7 || identifier==m7SUS4 || identifier==N7SUS4 || identifier==N7F5 || identifier==m7F5 || identifier==N7S5 || identifier==DIM7 || identifier==AUG7 || identifier==AUGM7 || identifier==N6 || identifier==m6 || identifier==ADD2 || identifier==ADD4 ) { number_of_notes = 4; } if( identifier==M9 || identifier==N9 || identifier==m9 || identifier==N7F9 || identifier==N7S9 || identifier==N7S11 || identifier==m7N11 || identifier==N7N13 || identifier==N9F5 || identifier==AUG7F9 || identifier==AUG9 || identifier==N69 || identifier==m69 ) { number_of_notes = 5; flag_five_notes_chord = true; } if( identifier==N11 || identifier==m11 ){ number_of_notes = 6; flag_six_notes_chord = true; } if( identifier==N13 || identifier==m13 ){ number_of_notes = 7; flag_seven_notes_chord = true; } if(cp->getKey_Layout()){ four_notes[0] = root_note; four_notes[1] = third_note; four_notes[2] = fifth_note; four_notes[3] = seventh_note; uint8_t i, j; for (i = 0; i < 4 - 1; i++){ for (j = 4 - 1; j >= i + 1; j--){ if (four_notes[j] < four_notes[j-1]) { swap(&four_notes[j], &four_notes[j-1]); } } } ichi = four_notes[0]; san = four_notes[1]; go = four_notes[2]; nana = four_notes[3]; for (int i = 0; i < 4; i++){ if( four_notes[i] == root_note ){ Serial.print("ルート音は "); Serial.print(i); Serial.println("番目の音 "); the_lowest_note_index = i;} }//*/ memset(four_notes, 0, sizeof(four_notes)); } if( number_of_notes == THREE_NOTES_CHORD ){ v1 = b_root_note + 24; v2 = b_third_note + 24; v3 = b_fifth_note + 24; v4 = b_root_note + 36; } else{ v1 = b_root_note + 24; v2 = b_third_note + 24; v3 = b_fifth_note + 24; v4 = b_seventh_note + 24; } } void set_song_keys( ChordProgression* cp, bool flag){ if( flag ){ if(cp->getKey() < 6) cp->setKey(cp->getKey()+1); } else{ if(-5 < cp->getKey()) cp->setKey(cp->getKey()-1); } } void midiNoteOnOff(uint8_t command, uint8_t pitch, uint8_t velocity, uint8_t channel) { if(pitch < X && pitch != 0){//if(pitch != X && pitch != 0){ Serial.write(command); Serial.write(pitch); Serial.write(velocity); } } void HandleNoteOff(uint8_t pitch, uint8_t velocity, uint8_t channel) { if(pitch < X && pitch != 0){ // uint8_t Off_channel = 0x80 + channel; uint8_t mididata[]={0x82, 0x84, Off_channel, pitch, 0x00}; Serial2.write((int)Off_channel); Serial2.write((int)pitch); Serial2.write((int)0x00); //MIDI.sendNoteOff(pitch, 0, channel); } } void HandleNoteOn(uint8_t pitch, uint8_t velocity, uint8_t channel) { if( velocity == 0x00 ) { HandleNoteOff(pitch,velocity,channel); return; } if(pitch < X && pitch != 0){ //if( pitch != 0x80 && pitch != 0 ) { uint8_t On_channel = 0x90 + channel; velocity += 30; if(127 < velocity) velocity = 127; //Serial.print("velocity is ");Serial.println(velocity); //Serial.print("pitch is ");Serial.println(pitch); print_intervals.mod12( pitch ); uint8_t mididata[]={0x82, 0x84, On_channel, pitch, velocity}; Serial2.write((int)On_channel); Serial2.write((int)pitch); Serial2.write((int)velocity); //MIDI.sendNoteOn(pitch, velocity, channel); } } void set_root( uint8_t *parameter_pitch, uint8_t suji ){ if( flag_compound ){ *parameter_pitch += suji+12; } else{ if( suji < 36 ){ *parameter_pitch += suji+12; Serial.println("Y");} else { *parameter_pitch += suji; Serial.println("N");} } } void show_tension( uint8_t td ){ switch( td ){ case TENSION_F9TH : Serial.println("テンションノートは、♭9th"); break; case TENSION_N9TH : Serial.println("テンションノートは、9th"); break; case TENSION_S9TH : Serial.println("テンションノートは、#9th"); break; case TENSION_N11TH : Serial.println("テンションノートは、11th"); break; case TENSION_S11TH : Serial.println("テンションノートは、#11th"); break; case TENSION_F13TH : Serial.println("テンションノートは、♭13th"); break; case TENSION_N13TH : Serial.println("テンションノートは、13th"); break; case TENSION_F14TH : Serial.println("テンションノートは、♭7th"); break; } } void set_tension( uint8_t *parameter_pitch, uint8_t suji ){ if( 72 < suji+36+tension_diff ){ *parameter_pitch += suji+24+tension_diff; } else { *parameter_pitch += suji+36+tension_diff; } show_tension( tension_diff ); } void set_tension( uint8_t *parameter_pitch, uint8_t suji, bool frag_td ){ *parameter_pitch += suji+24+tension_diff; show_tension( tension_diff ); } void set_ninth( uint8_t *parameter_pitch, uint8_t suji ){ if( 72 < suji+36+2 ){ *parameter_pitch += suji+24+2; } else { *parameter_pitch += suji+36+2; } } void set_eleventh( uint8_t *parameter_pitch, uint8_t suji ){ if( 72 < suji+36+5 ){ *parameter_pitch += suji+24+5; } else { *parameter_pitch += suji+36+5; } } void set_thirteenth( uint8_t *parameter_pitch, uint8_t suji ){ if( 72 < suji+36+9 ){ *parameter_pitch += suji+24+9; } else { *parameter_pitch += suji+36+9; } } uint8_t getCurrentSimultaneousTones(){ return current_simultaneous_tones; } void setCurrentSimultaneousTones(uint8_t cst){ current_simultaneous_tones = cst; } bool is_same_note_playing( int ind, uint8_t note ){ if( assigned_note[ ind ] == note ) return true; else return false; } void incrementCurrentSimultaneousTones(){ if( 0 <= current_simultaneous_tones && current_simultaneous_tones <= MAX_SIMULTANEOUS_TONES - 1 ){ current_simultaneous_tones++; } else{ //error } } void decrementCurrentSimultaneousTones(){ if( 1 <= current_simultaneous_tones && current_simultaneous_tones <= MAX_SIMULTANEOUS_TONES ){ current_simultaneous_tones--; } else{ //error } } void adding_one_element_last_array( uint8_t note_number ){ if( current_simultaneous_tones < MAX_SIMULTANEOUS_TONES ){ assigned_note[ current_simultaneous_tones ] = note_number; } else{ //error } } void moving_the_element_forward_one_by_one( int index ){ if( index < current_simultaneous_tones ){ if( current_simultaneous_tones == MAX_SIMULTANEOUS_TONES ){ assigned_note[ MAX_SIMULTANEOUS_TONES - 1 ] = 0; if( 0 <= index && index <= 62 ){ for( int i = index; i < current_simultaneous_tones - 1; i++ ){ assigned_note[ i ] = assigned_note[ i + 1 ]; } } }else if( 1 <= current_simultaneous_tones && current_simultaneous_tones < MAX_SIMULTANEOUS_TONES ){ for( int i = index; i < current_simultaneous_tones; i++ ){ assigned_note[ i ] = assigned_note[ i + 1 ]; } } else{ //error } } else{ //error } } void displaying_all_elements_in_array(){ if( current_simultaneous_tones == 0 ){ Serial.println("今出ている音はありません"); }else{ Serial.println( current_simultaneous_tones ); for( uint32_t i = 0; i < current_simultaneous_tones; i++ ){ Serial.print( i );Serial.print("番目の音は ");Serial.println( assigned_note[ i ] ); } } } void handleKeyOn(uint8_t cmd, unsigned char keyID, uint8_t velocity, uint8_t channel, ChordProgression* cp){ uint8_t pitch = 0; uint8_t plus_alpha = 0; if( cp->getIsPlus() ) plus_alpha = ONE_OCTAVE; if( !cp->getChordChangingMode() ){ if( keyID==DIY_KEY_LS3 || keyID==DIY_KEY_LS2 || keyID==DIY_KEY_LS1 || keyID==DIY_KEY_L3 || keyID==DIY_KEY_L4 || keyID==DIY_KEY_L5 || keyID==DIY_KEY_L6 || keyID==DIY_KEY_L7 || keyID==DIY_KEY_L8 || keyID==DIY_KEY_L9 || keyID==DIY_KEY_L10 || keyID==DIY_KEY_L11 || keyID==DIY_KEY_L12 || keyID==DIY_KEY_L13 || keyID==DIY_KEY_L14 || keyID==DIY_KEY_L15 || keyID==DIY_KEY_L16 || keyID==DIY_KEY_L17 || keyID==DIY_KEY_L18 || keyID==DIY_KEY_L19 || keyID==DIY_KEY_L20 || keyID==DIY_KEY_L21 || keyID==DIY_KEY_L22 || keyID==DIY_KEY_L23 || keyID==DIY_KEY_L24 || keyID==DIY_KEY_L25 || keyID==DIY_KEY_L26 || keyID==DIY_KEY_L27 ){ if(cp->getIsL_KeysOn()==false){ cp->setIsFirstLR(false); cp->setIsL_KeysOn(true); cp->setIsR_KeysOn(false); if(cp->getIndex() == 0){ if( !cp->getIsRightLast() ) { if( cp->getIsChangeSongStructureIndex() == true ){ set_intevals(cp); } else{ if( cp->getIsRightZero() == true ){ cp->setIsRightZero( false ); cp->setIndex( cp->getIndex()+1 ); set_intevals(cp); } else{ set_intevals(cp); } } } else{ cp->setIsRightLast( false ); cp->setIndex( cp->getIndex()+1 ); set_intevals(cp); } } else{ if( cp->getIndex() == ( cp->getTotalNumberOfCp() - 1) ){ if( cp->getIsChangeSongStructureIndex() == false && cp->getIsChangeIndex() == false ){ cp->setIndex(0); } else{ } set_intevals(cp); } else{ if( cp->getIsChangeSongStructureIndex() == false && cp->getIsChangeIndex() == false ){ cp->setIndex( cp->getIndex()+1 ); } else{ } set_intevals(cp); } //cp->setIsChangeSongStructureIndex( false ); //cp->setIsChangeIndex( false ); } cp->compare_index(); } cp->setIsChangeSongStructureIndex( false ); cp->setIsChangeIndex( false ); } if( keyID==DIY_KEY_RS3 || keyID==DIY_KEY_RS2 || keyID==DIY_KEY_RS1 || keyID==DIY_KEY_R3 || keyID==DIY_KEY_R4 || keyID==DIY_KEY_R5 || keyID==DIY_KEY_R6 || keyID==DIY_KEY_R7 || keyID==DIY_KEY_R8 || keyID==DIY_KEY_R9 || keyID==DIY_KEY_R10 || keyID==DIY_KEY_R11 || keyID==DIY_KEY_R12 || keyID==DIY_KEY_R13 || keyID==DIY_KEY_R14 || keyID==DIY_KEY_R15 || keyID==DIY_KEY_R16 || keyID==DIY_KEY_R17 || keyID==DIY_KEY_R18 || keyID==DIY_KEY_R19 || keyID==DIY_KEY_R20 || keyID==DIY_KEY_R21 || keyID==DIY_KEY_R22 || keyID==DIY_KEY_R23 || keyID==DIY_KEY_R24 || keyID==DIY_KEY_R25 || keyID==DIY_KEY_R26 || keyID==DIY_KEY_R27 ){ if(cp->getIsR_KeysOn()==false){ cp->setIsFirstLR(false); cp->setIsR_KeysOn(true); cp->setIsL_KeysOn(false); if(cp->getIndex() == 0){ if( cp->getIsChangeSongStructureIndex() == true || cp->getIsChangeIndex() == true ){ cp->setIsRightZero( true ); set_intevals(cp); } else{ cp->setIndex( cp->getIndex()+1 ); set_intevals(cp); } } else{ if( cp->getIndex() == ( cp->getTotalNumberOfCp() - 1) ){ cp->setIsRightLast( true ); if( cp->getIsChangeSongStructureIndex() == false && cp->getIsChangeIndex() == false ){ cp->setIndex(0); } else{ } set_intevals(cp); } else{ if( cp->getIsChangeSongStructureIndex() == false && cp->getIsChangeIndex() == false ){ cp->setIndex( cp->getIndex()+1 ); } else{ } set_intevals(cp); } //cp->setIsChangeSongStructureIndex( false ); //cp->setIsChangeIndex( false ); } cp->compare_index(); } cp->setIsChangeSongStructureIndex( false ); cp->setIsChangeIndex( false ); } byte next_semitone = 0; if( flag_next_compound ){ if( is_next_root_greater_than_next_compound ){ next_semitone = b_next_root_note - next_compound_diff; } else{ next_semitone = b_next_root_note + 12 - next_compound_diff; } }else{ next_semitone = b_next_root_note; } if( cp->getIsFirstLR() == true ){ if( keyID==KEY_EXP_L1_2 || keyID==KEY_EXP_L1_1 || keyID==KEY_EXP_R1_2 || keyID==KEY_EXP_R1_1 ){ keys_on_off[ keyID ] = 0; } }else{ switch( keyID ){ case KEY_EXP_R1_2 : keys_on_off[ keyID ] = next_semitone + semitone_up_down_2 + cp->getKey(); break; case KEY_EXP_R1_1 : keys_on_off[ keyID ] = next_semitone + semitone_up_down_1 + cp->getKey(); break; case KEY_EXP_L1_2 : keys_on_off[ keyID ] = next_semitone + semitone_up_down_2 + cp->getKey(); break; case KEY_EXP_L1_1 : keys_on_off[ keyID ] = next_semitone + semitone_up_down_1 + cp->getKey(); break; } } if(flag_compound){ if( keyID == DIY_KEY_RS1 || keyID == DIY_KEY_LS1 || keyID == KEY_EXP_R1 || keyID == KEY_EXP_L1 ){ if( is_root_greater_than_compound ){ keys_on_off[ keyID ] = b_root_note - compound_diff + cp->getKey(); } else{ keys_on_off[ keyID ] = b_root_note + 12 - compound_diff + cp->getKey(); if( b_third_note - 1 < keys_on_off[ keyID ] ){ b_third_note += ONE_OCTAVE; b_fifth_note += ONE_OCTAVE; b_seventh_note += ONE_OCTAVE; b_root_note += ONE_OCTAVE; root_note += ONE_OCTAVE; } } } } else{ if( keyID == DIY_KEY_RS1 || keyID == DIY_KEY_LS1 || keyID == KEY_EXP_R1 || keyID == KEY_EXP_L1 ){ keys_on_off[ keyID ] = b_root_note + cp->getKey(); } } if(flag_triad){ switch( keyID ){ case DIY_KEY_RS3 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case DIY_KEY_RS2 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_R2 : keys_on_off[ keyID ] = b_third_note + cp->getKey(); break; case KEY_EXP_R3 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_R4 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case KEY_EXP_R5 : keys_on_off[ keyID ] = b_third_note + 12 + cp->getKey(); break; case KEY_EXP_R6 : keys_on_off[ keyID ] = b_fifth_note + 12 + cp->getKey(); break; case KEY_EXP_R7 : keys_on_off[ keyID ] = b_root_note + 24 + cp->getKey(); break; case KEY_EXP_R8 : keys_on_off[ keyID ] = b_third_note + 24 + cp->getKey(); break; case KEY_EXP_R9 : keys_on_off[ keyID ] = b_fifth_note + 24 + cp->getKey(); break; case KEY_EXP_R10 : keys_on_off[ keyID ] = b_root_note + 36 + cp->getKey(); break; case KEY_EXP_R11 : keys_on_off[ keyID ] = b_third_note + 36 + cp->getKey(); break; case KEY_EXP_R12 : keys_on_off[ keyID ] = b_fifth_note + 36 + cp->getKey(); break; case KEY_EXP_R13 : keys_on_off[ keyID ] = b_root_note + 48 + cp->getKey(); break; case KEY_EXP_R14 : keys_on_off[ keyID ] = b_third_note + 48 + cp->getKey(); break; case KEY_EXP_R15 : keys_on_off[ keyID ] = b_fifth_note + 48 + cp->getKey(); break; case KEY_EXP_R16 : keys_on_off[ keyID ] = b_root_note + 60 + cp->getKey(); break; case KEY_EXP_R17 : keys_on_off[ keyID ] = b_third_note + 60 + cp->getKey(); break; case KEY_EXP_R18 : keys_on_off[ keyID ] = b_fifth_note + 60 + cp->getKey(); break; case DIY_KEY_LS3 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case DIY_KEY_LS2 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_L2 : keys_on_off[ keyID ] = b_third_note + cp->getKey(); break; case KEY_EXP_L3 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_L4 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case KEY_EXP_L5 : keys_on_off[ keyID ] = b_third_note + 12 + cp->getKey(); break; case KEY_EXP_L6 : keys_on_off[ keyID ] = b_fifth_note + 12 + cp->getKey(); break; case KEY_EXP_L7 : keys_on_off[ keyID ] = b_root_note + 24 + cp->getKey(); break; case KEY_EXP_L8 : keys_on_off[ keyID ] = b_third_note + 24 + cp->getKey(); break; case KEY_EXP_L9 : keys_on_off[ keyID ] = b_fifth_note + 24 + cp->getKey(); break; case KEY_EXP_L10 : keys_on_off[ keyID ] = b_root_note + 36 + cp->getKey(); break; case KEY_EXP_L11 : keys_on_off[ keyID ] = b_third_note + 36 + cp->getKey(); break; case KEY_EXP_L12 : keys_on_off[ keyID ] = b_fifth_note + 36 + cp->getKey(); break; case KEY_EXP_L13 : keys_on_off[ keyID ] = b_root_note + 48 + cp->getKey(); break; case KEY_EXP_L14 : keys_on_off[ keyID ] = b_third_note + 48 + cp->getKey(); break; case KEY_EXP_L15 : keys_on_off[ keyID ] = b_fifth_note + 48 + cp->getKey(); break; case KEY_EXP_L16 : keys_on_off[ keyID ] = b_root_note + 60 + cp->getKey(); break; case KEY_EXP_L17 : keys_on_off[ keyID ] = b_third_note + 60 + cp->getKey(); break; case KEY_EXP_L18 : keys_on_off[ keyID ] = b_fifth_note + 60 + cp->getKey(); break; case KEY_EXP_RU1 : keys_on_off[ keyID ] = b_root_note - 12 + cp->getKey(); break; case KEY_EXP_RU2 : set_tension( &pitch, root_note - 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU3 : set_tension( &pitch, root_note + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU4 : set_tension( &pitch, root_note + 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU5 : set_tension( &pitch, root_note + 24 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU6 : set_tension( &pitch, root_note + 36 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; /*case KEY_EXP_RU6 : set_tension( &pitch, root_note + 48 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break;*/ case KEY_EXP_LU1 : keys_on_off[ keyID ] = b_root_note - 12 + cp->getKey(); break; case KEY_EXP_LU2 : set_tension( &pitch, root_note - 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU3 : set_tension( &pitch, root_note + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU4 : set_tension( &pitch, root_note + 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU5 : set_tension( &pitch, root_note + 24 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU6 : set_tension( &pitch, root_note + 36 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; /*case KEY_EXP_LU6 : set_tension( &pitch, root_note + 48 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break;*/ } confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else{ switch( keyID ){ case DIY_KEY_RS3 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case DIY_KEY_RS2 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_R2 : keys_on_off[ keyID ] = b_third_note + cp->getKey(); break; case KEY_EXP_R3 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_R4 : keys_on_off[ keyID ] = b_seventh_note + cp->getKey(); break; case KEY_EXP_R5 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case KEY_EXP_R6 : keys_on_off[ keyID ] = b_third_note + 12 + cp->getKey(); break; case KEY_EXP_R7 : keys_on_off[ keyID ] = b_fifth_note + 12 + cp->getKey(); break; case KEY_EXP_R8 : keys_on_off[ keyID ] = b_seventh_note + 12 + cp->getKey(); break; case KEY_EXP_R9 : keys_on_off[ keyID ] = b_root_note + 24 + cp->getKey(); break; case KEY_EXP_R10 : keys_on_off[ keyID ] = b_third_note + 24 + cp->getKey(); break; case KEY_EXP_R11 : keys_on_off[ keyID ] = b_fifth_note + 24 + cp->getKey(); break; case KEY_EXP_R12 : keys_on_off[ keyID ] = b_seventh_note + 24 + cp->getKey(); break; case KEY_EXP_R13 : keys_on_off[ keyID ] = b_root_note + 36 + cp->getKey(); break; case KEY_EXP_R14 : keys_on_off[ keyID ] = b_third_note + 36 + cp->getKey(); break; case KEY_EXP_R15 : keys_on_off[ keyID ] = b_fifth_note + 36 + cp->getKey(); break; case KEY_EXP_R16 : keys_on_off[ keyID ] = b_seventh_note + 36 + cp->getKey(); break; case KEY_EXP_R17 : keys_on_off[ keyID ] = b_root_note + 48 + cp->getKey(); break; case KEY_EXP_R18 : keys_on_off[ keyID ] = b_third_note + 48 + cp->getKey(); break; case KEY_EXP_R19 : keys_on_off[ keyID ] = b_fifth_note + 48 + cp->getKey(); break; case KEY_EXP_R20 : keys_on_off[ keyID ] = b_seventh_note + 48 + cp->getKey(); break; case DIY_KEY_LS3 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case DIY_KEY_LS2 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_L2 : keys_on_off[ keyID ] = b_third_note + cp->getKey(); break; case KEY_EXP_L3 : keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); break; case KEY_EXP_L4 : keys_on_off[ keyID ] = b_seventh_note + cp->getKey(); break; case KEY_EXP_L5 : keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); break; case KEY_EXP_L6 : keys_on_off[ keyID ] = b_third_note + 12 + cp->getKey(); break; case KEY_EXP_L7 : keys_on_off[ keyID ] = b_fifth_note + 12 + cp->getKey(); break; case KEY_EXP_L8 : keys_on_off[ keyID ] = b_seventh_note + 12 + cp->getKey(); break; case KEY_EXP_L9 : keys_on_off[ keyID ] = b_root_note + 24 + cp->getKey(); break; case KEY_EXP_L10 : keys_on_off[ keyID ] = b_third_note + 24 + cp->getKey(); break; case KEY_EXP_L11 : keys_on_off[ keyID ] = b_fifth_note + 24 + cp->getKey(); break; case KEY_EXP_L12 : keys_on_off[ keyID ] = b_seventh_note + 24 + cp->getKey(); break; case KEY_EXP_L13 : keys_on_off[ keyID ] = b_root_note + 36 + cp->getKey(); break; case KEY_EXP_L14 : keys_on_off[ keyID ] = b_third_note + 36 + cp->getKey(); break; case KEY_EXP_L15 : keys_on_off[ keyID ] = b_fifth_note + 36 + cp->getKey(); break; case KEY_EXP_L16 : keys_on_off[ keyID ] = b_seventh_note + 36 + cp->getKey(); break; case KEY_EXP_L17 : keys_on_off[ keyID ] = b_root_note + 48 + cp->getKey(); break; case KEY_EXP_L18 : keys_on_off[ keyID ] = b_third_note + 48 + cp->getKey(); break; case KEY_EXP_L19 : keys_on_off[ keyID ] = b_fifth_note + 48 + cp->getKey(); break; case KEY_EXP_L20 : keys_on_off[ keyID ] = b_seventh_note + 48 + cp->getKey(); break; case KEY_EXP_RU1 : keys_on_off[ keyID ] = b_root_note - 12 + cp->getKey(); break; case KEY_EXP_RU2 : set_tension( &pitch, root_note - 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU3 : set_tension( &pitch, root_note + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU4 : set_tension( &pitch, root_note + 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU5 : set_tension( &pitch, root_note + 24 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_RU6 : set_tension( &pitch, root_note + 36 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; /*case KEY_EXP_RU6 : set_tension( &pitch, root_note + 48 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break;*/ case KEY_EXP_LU1 : keys_on_off[ keyID ] = b_root_note - 12 + cp->getKey(); break; case KEY_EXP_LU2 : set_tension( &pitch, root_note - 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU3 : set_tension( &pitch, root_note + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU4 : set_tension( &pitch, root_note + 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU5 : set_tension( &pitch, root_note + 24 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; case KEY_EXP_LU6 : set_tension( &pitch, root_note + 36 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break; /*case KEY_EXP_LU6 : set_tension( &pitch, root_note + 48 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; break;*/ } confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } } else{ if( keyID == KEY_EXP_LB ){ if( cp->getIndex() == ( cp->getTotalNumberOfCp() - 1) ){ cp->setIndex(0); } else{ cp->setIndex( cp->getIndex()+1 ); } set_intevals(cp); cp->compare_index(); } if( keyID==KEY_EXP_L1_2 || keyID==KEY_EXP_L1_1 ){ if( isSemitoneKeysOn == false ){ isSemitoneKeysOn = true; if( cp->getIndex() == ( cp->getTotalNumberOfCp() - 1) ){ cp->setIndex(0); } else{ cp->setIndex( cp->getIndex()+1 ); } set_intevals(cp); } } if( keyID == KEY_EXP_L1 || keyID == KEY_EXP_L3 ){ isSemitoneKeysOn = false; } if(flag_compound){ if( keyID == KEY_EXP_L1_1 ){ keys_on_off[keyID] = b_root_note + 12 + cp->getKey() - compound_diff + semitone_up_down_1; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L1_2 ){ keys_on_off[keyID] = b_root_note + 12 + cp->getKey() - compound_diff + semitone_up_down_2; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L1 ){ keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey() - compound_diff ; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } } else{ if( keyID == KEY_EXP_L1_1 ){ keys_on_off[keyID] = b_root_note + cp->getKey() + semitone_up_down_1; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L1_2 ){ keys_on_off[keyID] = b_root_note + cp->getKey() + semitone_up_down_2; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L1 ){ keys_on_off[ keyID ] = b_root_note + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } } if(flag_triad){ if( keyID == KEY_EXP_L2 ){ keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L3 ){ keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L4 ){ keys_on_off[ keyID ] = b_third_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L5 ){ keys_on_off[ keyID ] = b_fifth_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L6 ){ switch( number_of_notes ){ case THREE_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 6 ] = 0; keys_on_off[ 7 ] = 0; keys_on_off[ 8 ] = 0; break; case FOUR_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = 0; keys_on_off[ 7 ] = 0; keys_on_off[ 8 ] = 0; break; case FIVE_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = b_root_note + 24 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 7 ] = 0; keys_on_off[ 8 ] = 0; break; case SIX_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = b_root_note + 24 + 2 + cp->getKey(); keys_on_off[ 7 ] = b_root_note + 24 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 8 ] = 0; break; case SEVEN_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = b_root_note + 24 + 2 + cp->getKey(); keys_on_off[ 7 ] = b_root_note + 24 + 5 + cp->getKey(); keys_on_off[ 8 ] = b_root_note + 24 + tension_diff + cp->getKey(); show_tension( tension_diff ); break; } confirm_if_assigned_note( 2, keys_on_off[ 2 ], velocity, channel ); confirm_if_assigned_note( 3, keys_on_off[ 3 ], velocity, channel ); confirm_if_assigned_note( 4, keys_on_off[ 4 ], velocity, channel ); confirm_if_assigned_note( 5, keys_on_off[ 5 ], velocity, channel ); confirm_if_assigned_note( 6, keys_on_off[ 6 ], velocity, channel ); confirm_if_assigned_note( 7, keys_on_off[ 7 ], velocity, channel ); confirm_if_assigned_note( 8, keys_on_off[ 8 ], velocity, channel ); } else if( keyID == KEY_EXP_L7 ){ keys_on_off[ keyID ] = b_third_note + 24 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L8 ){ keys_on_off[ keyID ] = b_fifth_note + 24 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L9 ){ switch( number_of_notes ){ case THREE_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 13 ] = 0; keys_on_off[ 14 ] = 0; keys_on_off[ 15 ] = 0; break; case FOUR_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = 0; keys_on_off[ 14 ] = 0; keys_on_off[ 15 ] = 0; break; case FIVE_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = b_root_note + 36 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 14 ] = 0; keys_on_off[ 15 ] = 0; break; case SIX_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = b_root_note + 36 + 2 + cp->getKey(); keys_on_off[ 14 ] = b_root_note + 36 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 15 ] = 0; break; case SEVEN_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = b_root_note + 36 + 2 + cp->getKey(); keys_on_off[ 14 ] = b_root_note + 36 + 5 + cp->getKey(); keys_on_off[ 15 ] = b_root_note + 36 + tension_diff + cp->getKey(); show_tension( tension_diff ); break; } confirm_if_assigned_note( 9, keys_on_off[ 9 ], velocity, channel ); confirm_if_assigned_note( 10, keys_on_off[ 10 ], velocity, channel ); confirm_if_assigned_note( 11, keys_on_off[ 11 ], velocity, channel ); confirm_if_assigned_note( 12, keys_on_off[ 12 ], velocity, channel ); confirm_if_assigned_note( 13, keys_on_off[ 13 ], velocity, channel ); confirm_if_assigned_note( 14, keys_on_off[ 14 ], velocity, channel ); confirm_if_assigned_note( 15, keys_on_off[ 15 ], velocity, channel ); } else if( keyID == KEY_EXP_L10 ){ keys_on_off[ keyID ] = b_third_note + 36 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L11 ){ keys_on_off[ keyID ] = b_fifth_note + 36 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L12 ){ switch( number_of_notes ){ case THREE_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = 0; keys_on_off[ 20 ] = 0; keys_on_off[ 21 ] = 0; keys_on_off[ 22 ] = 0; break; case FOUR_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = 0; keys_on_off[ 21 ] = 0; keys_on_off[ 22 ] = 0; break; case FIVE_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = b_root_note + 48 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 21 ] = 0; keys_on_off[ 22 ] = 0; break; case SIX_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = b_root_note + 48 + 2 + cp->getKey(); keys_on_off[ 21 ] = b_root_note + 48 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 22 ] = 0; break; case SEVEN_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = b_root_note + 48 + 2 + cp->getKey(); keys_on_off[ 21 ] = b_root_note + 48 + 5 + cp->getKey(); keys_on_off[ 22 ] = b_root_note + 48 + tension_diff + cp->getKey(); show_tension( tension_diff ); break; } confirm_if_assigned_note( 16, keys_on_off[ 16 ], velocity, channel ); confirm_if_assigned_note( 17, keys_on_off[ 17 ], velocity, channel ); confirm_if_assigned_note( 18, keys_on_off[ 18 ], velocity, channel ); confirm_if_assigned_note( 19, keys_on_off[ 19 ], velocity, channel ); confirm_if_assigned_note( 20, keys_on_off[ 20 ], velocity, channel ); confirm_if_assigned_note( 21, keys_on_off[ 21 ], velocity, channel ); confirm_if_assigned_note( 22, keys_on_off[ 22 ], velocity, channel ); } else if( keyID == KEY_EXP_LU1 ){ set_tension( &pitch, root_note - 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU2 ){ set_tension( &pitch, root_note + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU3 ){ keys_on_off[ keyID ] = b_root_note + 24 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU4 ){ set_tension( &pitch, root_note + 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU5 ){ keys_on_off[ keyID ] = b_root_note + 36 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU6 ){ set_tension( &pitch, root_note + 24 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } } else{ if( keyID == KEY_EXP_L2 ){ keys_on_off[ keyID ] = b_fifth_note + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L3 ){ keys_on_off[ keyID ] = b_root_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L4 ){ keys_on_off[ keyID ] = b_third_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L5 ){ keys_on_off[ keyID ] = b_seventh_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L6 ){ switch( number_of_notes ){ case THREE_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 6 ] = 0; keys_on_off[ 7 ] = 0; keys_on_off[ 8 ] = 0; break; case FOUR_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = 0; keys_on_off[ 7 ] = 0; keys_on_off[ 8 ] = 0; break; case FIVE_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = b_root_note + 24 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 7 ] = 0; keys_on_off[ 8 ] = 0; break; case SIX_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = b_root_note + 24 + 2 + cp->getKey(); keys_on_off[ 7 ] = b_root_note + 24 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 8 ] = 0; break; case SEVEN_NOTES_CHORD : keys_on_off[ 2 ] = b_root_note + 12 + cp->getKey(); keys_on_off[ 3 ] = b_third_note + 12 + cp->getKey(); keys_on_off[ 4 ] = b_fifth_note + 12 + cp->getKey(); keys_on_off[ 5 ] = b_seventh_note + 12 + cp->getKey(); keys_on_off[ 6 ] = b_root_note + 24 + 2 + cp->getKey(); keys_on_off[ 7 ] = b_root_note + 24 + 5 + cp->getKey(); keys_on_off[ 8 ] = b_root_note + 24 + tension_diff + cp->getKey(); show_tension( tension_diff ); break; } confirm_if_assigned_note( 2, keys_on_off[ 2 ], velocity, channel ); confirm_if_assigned_note( 3, keys_on_off[ 3 ], velocity, channel ); confirm_if_assigned_note( 4, keys_on_off[ 4 ], velocity, channel ); confirm_if_assigned_note( 5, keys_on_off[ 5 ], velocity, channel ); confirm_if_assigned_note( 6, keys_on_off[ 6 ], velocity, channel ); confirm_if_assigned_note( 7, keys_on_off[ 7 ], velocity, channel ); confirm_if_assigned_note( 8, keys_on_off[ 8 ], velocity, channel ); } else if( keyID == KEY_EXP_L7 ){ keys_on_off[ keyID ] = b_third_note + 24 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L8 ){ keys_on_off[ keyID ] = b_seventh_note + 24 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L9 ){ switch( number_of_notes ){ case THREE_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 13 ] = 0; keys_on_off[ 14 ] = 0; keys_on_off[ 15 ] = 0; break; case FOUR_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = 0; keys_on_off[ 14 ] = 0; keys_on_off[ 15 ] = 0; break; case FIVE_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = b_root_note + 36 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 14 ] = 0; keys_on_off[ 15 ] = 0; break; case SIX_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = b_root_note + 36 + 2 + cp->getKey(); keys_on_off[ 14 ] = b_root_note + 36 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 15 ] = 0; break; case SEVEN_NOTES_CHORD : keys_on_off[ 9 ] = b_root_note + 24 + cp->getKey(); keys_on_off[ 10 ] = b_third_note + 24 + cp->getKey(); keys_on_off[ 11 ] = b_fifth_note + 24 + cp->getKey(); keys_on_off[ 12 ] = b_seventh_note + 24 + cp->getKey(); keys_on_off[ 13 ] = b_root_note + 36 + 2 + cp->getKey(); keys_on_off[ 14 ] = b_root_note + 36 + 5 + cp->getKey(); keys_on_off[ 15 ] = b_root_note + 36 + tension_diff + cp->getKey(); show_tension( tension_diff ); break; } confirm_if_assigned_note( 9, keys_on_off[ 9 ], velocity, channel ); confirm_if_assigned_note( 10, keys_on_off[ 10 ], velocity, channel ); confirm_if_assigned_note( 11, keys_on_off[ 11 ], velocity, channel ); confirm_if_assigned_note( 12, keys_on_off[ 12 ], velocity, channel ); confirm_if_assigned_note( 13, keys_on_off[ 13 ], velocity, channel ); confirm_if_assigned_note( 14, keys_on_off[ 14 ], velocity, channel ); confirm_if_assigned_note( 15, keys_on_off[ 15 ], velocity, channel ); } else if( keyID == KEY_EXP_L10 ){ keys_on_off[ keyID ] = b_third_note + 36 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L11 ){ keys_on_off[ keyID ] = b_seventh_note + 36 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_L12 ){ switch( number_of_notes ){ case THREE_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = 0; keys_on_off[ 20 ] = 0; keys_on_off[ 21 ] = 0; keys_on_off[ 22 ] = 0; break; case FOUR_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = 0; keys_on_off[ 21 ] = 0; keys_on_off[ 22 ] = 0; break; case FIVE_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = b_root_note + 48 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 21 ] = 0; keys_on_off[ 22 ] = 0; break; case SIX_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = b_root_note + 48 + 2 + cp->getKey(); keys_on_off[ 21 ] = b_root_note + 48 + tension_diff + cp->getKey(); show_tension( tension_diff ); keys_on_off[ 22 ] = 0; break; case SEVEN_NOTES_CHORD : keys_on_off[ 16 ] = b_root_note + 36 + cp->getKey(); keys_on_off[ 17 ] = b_third_note + 36 + cp->getKey(); keys_on_off[ 18 ] = b_fifth_note + 36 + cp->getKey(); keys_on_off[ 19 ] = b_seventh_note + 36 + cp->getKey(); keys_on_off[ 20 ] = b_root_note + 48 + 2 + cp->getKey(); keys_on_off[ 21 ] = b_root_note + 48 + 5 + cp->getKey(); keys_on_off[ 22 ] = b_root_note + 48 + tension_diff + cp->getKey(); show_tension( tension_diff ); break; } confirm_if_assigned_note( 16, keys_on_off[ 16 ], velocity, channel ); confirm_if_assigned_note( 17, keys_on_off[ 17 ], velocity, channel ); confirm_if_assigned_note( 18, keys_on_off[ 18 ], velocity, channel ); confirm_if_assigned_note( 19, keys_on_off[ 19 ], velocity, channel ); confirm_if_assigned_note( 20, keys_on_off[ 20 ], velocity, channel ); confirm_if_assigned_note( 21, keys_on_off[ 21 ], velocity, channel ); confirm_if_assigned_note( 22, keys_on_off[ 22 ], velocity, channel ); } else if( keyID == KEY_EXP_LU1 ){ keys_on_off[ keyID ] = b_fifth_note + 12 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU2 ){ set_tension( &pitch, root_note + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU3 ){ keys_on_off[ keyID ] = b_root_note + 24 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU4 ){ set_tension( &pitch, root_note + 12 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU5 ){ keys_on_off[ keyID ] = b_root_note + 36 + cp->getKey(); confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } else if( keyID == KEY_EXP_LU6 ){ set_tension( &pitch, root_note + 24 + cp->getKey(), 0 ); keys_on_off[ keyID ] = pitch; confirm_if_assigned_note( keyID, keys_on_off[ keyID ], velocity, channel ); } } } } void handleKeyOff( uint8_t cmd, uint8_t keyID, uint8_t velocity, uint8_t channel, ChordProgression* cp ){ if( !cp->getChordChangingMode() ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else{ if( keyID == KEY_EXP_L1 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L2 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L3 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L4 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L5 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L6 ){ note_off_assign_zero( 2, keys_on_off[ 2 ], 0, channel); note_off_assign_zero( 3, keys_on_off[ 3 ], 0, channel); note_off_assign_zero( 4, keys_on_off[ 4 ], 0, channel); note_off_assign_zero( 5, keys_on_off[ 5 ], 0, channel); note_off_assign_zero( 6, keys_on_off[ 6 ], 0, channel); note_off_assign_zero( 7, keys_on_off[ 7 ], 0, channel); note_off_assign_zero( 8, keys_on_off[ 8 ], 0, channel); } else if( keyID == KEY_EXP_L7 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L8 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L9 ){ note_off_assign_zero( 9, keys_on_off[ 9 ], 0, channel); note_off_assign_zero( 10, keys_on_off[ 10 ], 0, channel); note_off_assign_zero( 11, keys_on_off[ 11 ], 0, channel); note_off_assign_zero( 12, keys_on_off[ 12 ], 0, channel); note_off_assign_zero( 13, keys_on_off[ 13 ], 0, channel); note_off_assign_zero( 14, keys_on_off[ 14 ], 0, channel); note_off_assign_zero( 15, keys_on_off[ 15 ], 0, channel); } else if( keyID == KEY_EXP_L10 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L11 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L12 ){ note_off_assign_zero( 16, keys_on_off[ 16 ], 0, channel); note_off_assign_zero( 17, keys_on_off[ 17 ], 0, channel); note_off_assign_zero( 18, keys_on_off[ 18 ], 0, channel); note_off_assign_zero( 19, keys_on_off[ 19 ], 0, channel); note_off_assign_zero( 20, keys_on_off[ 20 ], 0, channel); note_off_assign_zero( 21, keys_on_off[ 21 ], 0, channel); note_off_assign_zero( 22, keys_on_off[ 22 ], 0, channel); } else if( keyID == KEY_EXP_LU1 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_LU2 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_LU3 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_LU4 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_LU5 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_LU6 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L1_1 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } else if( keyID == KEY_EXP_L1_2 ){ note_off_assign_zero( keyID, keys_on_off[ keyID ], 0, channel); } } } void confirm_if_assigned_note( uint8_t index_of_the_array, uint8_t a_note, uint8_t velocity, uint8_t channel ){ if( a_note != 0 ){ bool flag_same_note = false; uint8_t num = 0b11111111; for( uint8_t i = 0; i < NUMBER_OF_KEYS; i++ ){ //for( uint8_t i = 0; i < 60; i++ ){ if( index_of_the_array == i ) continue; if( keys_on_off[ i ] == 0 ) continue; else if( keys_on_off[ i ] == a_note ){ flag_same_note = true; num = i; break; } } if( flag_same_note ){ HandleNoteOff( keys_on_off[ num ], 0, channel ); keys_on_off[ num ] = 0; HandleNoteOn( keys_on_off[ index_of_the_array ], velocity, channel ); } else{ HandleNoteOn( keys_on_off[ index_of_the_array ], velocity, channel ); } } } void all_note_off(){ for( uint8_t i = 0; i < NUMBER_OF_KEYS; i++ ){ if( keys_on_off[ i ] == 0 ) continue; else { HandleNoteOff( keys_on_off[ i ], 0, MIDICH1 ); keys_on_off[ i ] = 0; } } } void note_off_assign_zero( uint8_t index_of_the_array, uint8_t a_note, uint8_t velocity, uint8_t channel ){ if( a_note != 0 ){ HandleNoteOff(a_note, 0, channel); keys_on_off[ index_of_the_array ] = 0; } } }; class Switch { protected: bool isSwitchOn[ NUMBER_OF_SWITCHES_FOR_KEYS ]; uint8_t isPressredFirst[ NUMBER_OF_KEYS ]; byte recently_note[ NUMBER_OF_KEYS ]; unsigned long time_pressed_switch[ NUMBER_OF_SWITCHES_FOR_KEYS ]; unsigned long temporal_difference[ NUMBER_OF_KEYS ]; byte diff[ NUMBER_OF_KEYS ]; byte velocity[ NUMBER_OF_KEYS ]; bool pressed_keys_or_not[ NUMBER_OF_KEYS ]; public: Switch() { memset(isSwitchOn, false, sizeof(isSwitchOn)); memset(isPressredFirst, 0xFF, sizeof(isPressredFirst)); memset(recently_note, 0, sizeof(recently_note)); //memset(note_on_off, false, sizeof(note_on_off)); //memset(note_on_time, 0, sizeof(note_on_time)); memset(time_pressed_switch, 0, sizeof(time_pressed_switch)); memset(temporal_difference, 0, sizeof(temporal_difference)); memset(diff, 0, sizeof(diff)); memset(velocity, 0, sizeof(velocity)); memset(pressed_keys_or_not, false, sizeof(pressed_keys_or_not)); } void init_switches(){ memset(isSwitchOn, false, sizeof(isSwitchOn)); memset(isPressredFirst, 0xFF, sizeof(isPressredFirst)); memset(recently_note, 0, sizeof(recently_note)); memset(time_pressed_switch, 0, sizeof(time_pressed_switch)); memset(temporal_difference, 0, sizeof(temporal_difference)); memset(diff, 0, sizeof(diff)); memset(velocity, 0, sizeof(velocity)); memset(pressed_keys_or_not, false, sizeof(pressed_keys_or_not)); } bool getIsSwitchOn( ButtonID button_id ){ return isSwitchOn[ button_id ]; } void setIsSwitchOn( ButtonID button_id, bool iso ){ isSwitchOn[ button_id ] = iso; } uint8_t getIsPressredFirst( DIYKeyID diy_key_id ){ return isPressredFirst[ diy_key_id ]; } void setIsPressredFirst( DIYKeyID diy_key_id, uint8_t ipf ){ isPressredFirst[ diy_key_id ] = ipf; } unsigned long getTimePressedSwitch( ButtonID button_id ){ return time_pressed_switch[ button_id ]; } //DIYKeyID getDiyKeyIdArray( ButtonID button_id ){ return diy_key_id_array[ button_id ]; } void set_time(ButtonID button_id){ time_pressed_switch[ button_id ] = millis(); isSwitchOn[ button_id ] = true; } void trigger_time_on(ButtonID button_id){ time_pressed_switch[button_id] = millis(); pressed_keys_or_not[button_id] = true; } void pressedkey( ButtonID button_id, bool calculation_type, DIYKeyID diy_key_id, Interval* iv, ChordProgression* cp ){ byte key_id = 0; if( calculation_type ) key_id = button_id + 1; else key_id = button_id - 1; if( isSwitchOn[ button_id ] && isSwitchOn[ key_id ] ){ temporal_difference[ diy_key_id ] = time_pressed_switch[ button_id ] - time_pressed_switch[ key_id ]; unsigned long hiku = 0; if( temporal_difference[ diy_key_id ] <= 5 ){ hiku = 0; } else if( 6 <= temporal_difference[ diy_key_id ] && temporal_difference[ diy_key_id ] <= 5 + 87 ){ hiku = temporal_difference[ diy_key_id ] - 5; } else if( 5 + 87 < temporal_difference[ diy_key_id ] ){ hiku = 87; } velocity[ diy_key_id ] = 127 - hiku; Serial.print("音量は"); Serial.println( velocity[ diy_key_id ] ); iv->handleKeyOn( 0x90, diy_key_id, velocity[ diy_key_id ], 1, cp); //isPressredFirst[ diy_key_id ] = 0xFF; time_pressed_switch[ button_id ] = 0; time_pressed_switch[ key_id ] = 0; temporal_difference[ diy_key_id ] = 0; velocity[ diy_key_id ] = 0; pressed_keys_or_not[ diy_key_id ] = true; } } void releasedkey( ButtonID button_id, bool calculation_type, DIYKeyID diy_key_id, Interval* iv, ChordProgression* cp ){ byte key_id = 0; if( calculation_type ) key_id = button_id + 1; else key_id = button_id - 1; if( pressed_keys_or_not[ diy_key_id ] && !isSwitchOn[ button_id ] && !isSwitchOn[ key_id ] ){ iv->handleKeyOff( 0x80, diy_key_id, 0, 1, cp); pressed_keys_or_not[ diy_key_id ] = false; } } }; ChordProgression chord_progression; Interval interval; Switch switch_class; uint32_t loop_0_7 = 0; bool isStart; DIYKeyID diy_key_id_array[]={ //0~9 DIY_KEY_LS3, DIY_KEY_LS3, DIY_KEY_LS2, DIY_KEY_LS2, DIY_KEY_LS1, DIY_KEY_LS1, DIY_KEY_RS3, DIY_KEY_RS3, DIY_KEY_RS2, DIY_KEY_RS2, //10~63 DIY_KEY_L1, DIY_KEY_L1, DIY_KEY_L2, DIY_KEY_L2, DIY_KEY_L3, DIY_KEY_L3, DIY_KEY_L4, DIY_KEY_L4, DIY_KEY_L5, DIY_KEY_L5, DIY_KEY_L6, DIY_KEY_L6, DIY_KEY_L7, DIY_KEY_L7, DIY_KEY_L8, DIY_KEY_L8, DIY_KEY_L9, DIY_KEY_L9, DIY_KEY_L10, DIY_KEY_L10, DIY_KEY_L11, DIY_KEY_L11, DIY_KEY_L12, DIY_KEY_L12, DIY_KEY_L13, DIY_KEY_L13, DIY_KEY_L14, DIY_KEY_L14, DIY_KEY_L15, DIY_KEY_L15, DIY_KEY_L16, DIY_KEY_L16, DIY_KEY_L17, DIY_KEY_L17, DIY_KEY_L18, DIY_KEY_L18, DIY_KEY_L19, DIY_KEY_L19, DIY_KEY_L20, DIY_KEY_L20, DIY_KEY_L21, DIY_KEY_L21, DIY_KEY_L22, DIY_KEY_L22, DIY_KEY_L23, DIY_KEY_L23, DIY_KEY_L24, DIY_KEY_L24, DIY_KEY_L25, DIY_KEY_L25, DIY_KEY_L26, DIY_KEY_L26, DIY_KEY_L27, DIY_KEY_L27, //64,65 DIY_KEY_RS1, DIY_KEY_RS1, //66~119 DIY_KEY_R1, DIY_KEY_R1, DIY_KEY_R2, DIY_KEY_R2, DIY_KEY_R3, DIY_KEY_R3, DIY_KEY_R4, DIY_KEY_R4, DIY_KEY_R5, DIY_KEY_R5, DIY_KEY_R6, DIY_KEY_R6, DIY_KEY_R7, DIY_KEY_R7, DIY_KEY_R8, DIY_KEY_R8, DIY_KEY_R9, DIY_KEY_R9, DIY_KEY_R10, DIY_KEY_R10, DIY_KEY_R11, DIY_KEY_R11, DIY_KEY_R12, DIY_KEY_R12, DIY_KEY_R13, DIY_KEY_R13, DIY_KEY_R14, DIY_KEY_R14, DIY_KEY_R15, DIY_KEY_R15, DIY_KEY_R16, DIY_KEY_R16, DIY_KEY_R17, DIY_KEY_R17, DIY_KEY_R18, DIY_KEY_R18, DIY_KEY_R19, DIY_KEY_R19, DIY_KEY_R20, DIY_KEY_R20, DIY_KEY_R21, DIY_KEY_R21, DIY_KEY_R22, DIY_KEY_R22, DIY_KEY_R23, DIY_KEY_R23, DIY_KEY_R24, DIY_KEY_R24, DIY_KEY_R25, DIY_KEY_R25, DIY_KEY_R26, DIY_KEY_R26, DIY_KEY_R27, DIY_KEY_R27, }; class MyButtonHandler : public ButtonHandler { public: void handlePressedSwitches( ButtonID button_id, bool calculation_type ){ switch_class.set_time( button_id ); DIYKeyID diy = diy_key_id_array[ button_id ]; if( switch_class.getIsPressredFirst( diy ) == 0xFF ){ switch_class.setIsPressredFirst( diy, button_id ); } else{ switch_class.pressedkey( button_id, calculation_type, diy, &interval, &chord_progression ); }// } void pressed( ButtonID button_id ) { //if( ( KEY_L1_A <= button_id && button_id <= KEY_L27_B ) || // ( KEY_R1_A <= button_id && button_id <= KEY_R27_B ) ){ if( KEY_LS3_A <= button_id && button_id <= KEY_R27_B ){ if( !( button_id % 2 ) ) handlePressedSwitches( button_id, TYPE_A ); else handlePressedSwitches( button_id, TYPE_B ); } switch(button_id){ case CHANGE_CHORDCHANGINGMODE: interval.all_note_off(); switch_class.init_switches(); if( !button_input.isOn( DECREMENT_BUTTON ) ){ if( !chord_progression.getChordChangingMode() ){ chord_progression.setChordChangingMode(true); chord_progression.compare_index(); interval.set_intevals(&chord_progression); }//falseならtrue else{ chord_progression.setChordChangingMode(false); chord_progression.compare_index(); interval.set_intevals( &chord_progression ); } }else{ chord_progression.song_init(); if( chord_progression.getChordChangingMode() ){ if( chord_progression.getKey_Layout() ){ chord_progression.setIsBasicBefore( false ); } else{ chord_progression.setIsBasicBefore( true ); } chord_progression.setKey_Layout(true); } else{ chord_progression.setKey_Layout( true ); } interval.set_intevals(&chord_progression); } break; case CHANGE_INDEX: chord_progression.setIsChangeIndex( true ); interval.all_note_off(); switch_class.init_switches(); if( !button_input.isOn( DECREMENT_BUTTON ) ){ if( chord_progression.getIndex() == (chord_progression.getTotalNumberOfCp() - 1) ) { chord_progression.setIndex(0); } else { chord_progression.setIndex( chord_progression.getIndex()+1 ); } interval.set_intevals( &chord_progression ); chord_progression.compare_index(); }else{ if( chord_progression.getIndex() != 0 ){ chord_progression.setIndex( chord_progression.getIndex()-1 ); interval.set_intevals(&chord_progression); } chord_progression.compare_index_less_than(); } Serial.print("Index is ");Serial.println(chord_progression.getIndex()); chord_progression.setIsRightLast( false ); chord_progression.setIsRightZero( false ); break; case DECREMENT_BUTTON: break; case CHANGE_KEY: interval.all_note_off(); switch_class.init_switches(); if( !button_input.isOn( DECREMENT_BUTTON ) ){ interval.set_song_keys(&chord_progression, KEY_UP); }else{ interval.set_song_keys(&chord_progression, KEY_DOWN); } Serial.print("Song KEY is ");Serial.println(chord_progression.getKey()); interval.set_intevals(&chord_progression); if( chord_progression.getIsFirstLR() ){ } else{ } break; case CHANGE_SONG_STRUCTURE_INDEX: { chord_progression.setIsChangeSongStructureIndex( true ); interval.all_note_off(); switch_class.init_switches(); int cpgi = chord_progression.getIndex(); int cpgt = chord_progression.getTrack(); int cpgssi = chord_progression.getSongStructureIndex(); if( !button_input.isOn( DECREMENT_BUTTON ) ){ if( chord_progression.getSongStructureIndex() == chord_progression.getTotalSongStructureIndex() - 1 ){ chord_progression.setSongStructureIndex( 0 ); } else{ chord_progression.setSongStructureIndex( chord_progression.getSongStructureIndex() + 1 ); } } else{ if( chord_progression.getSongStructureIndex() == 0 ){ //chord_progression.setSongStructureIndex( 0 ); } else{ if( cpgi - song_structure[ cpgt ][ cpgssi ] == 0 ){ chord_progression.setSongStructureIndex( chord_progression.getSongStructureIndex() - 1 ); } else{ chord_progression.setSongStructureIndex( chord_progression.getSongStructureIndex() ); } } } chord_progression.setIndex( song_structure[ chord_progression.getTrack() ][ chord_progression.getSongStructureIndex() ] ); Serial.print("Index is ");Serial.println(chord_progression.getIndex()); if( !chord_progression.getChordChangingMode() ){ } chord_progression.compare_index(); interval.set_intevals(&chord_progression); chord_progression.setIsRightLast( false ); chord_progression.setIsRightZero( false ); break; } case CHANGE_TRACK: interval.all_note_off(); switch_class.init_switches(); if( !button_input.isOn( DECREMENT_BUTTON ) ){ if(chord_progression.getTrack() != ( HOW_MANY_SONGS -1 )){ chord_progression.setTrack(chord_progression.getTrack()+1); } else{ chord_progression.track_init(); } }else{ if( chord_progression.getTrack() != 0 ){ chord_progression.setTrack(chord_progression.getTrack()-1); }else{ } } chord_progression.song_init(); chord_progression.setKey_Layout( true ); interval.set_intevals(&chord_progression); break; case CHANGE_KEYLAYOUT: if( !chord_progression.getKey_Layout() ){ chord_progression.setKey_Layout(true); } else { chord_progression.setKey_Layout(false); } interval.set_intevals(&chord_progression); if( chord_progression.getIsFirstLR() ){ } else{ } break; case CHANGE_PLUS_MODE: interval.all_note_off(); switch_class.init_switches(); if( !button_input.isOn( DECREMENT_BUTTON ) ){ byte now_state = chord_progression.getKeyLayoutThreeState(); if( now_state == 2 ) chord_progression.setKeyLayoutThreeState( 0 ); else chord_progression.setKeyLayoutThreeState( now_state + 1 ); switch( chord_progression.getKeyLayoutThreeState() ){ case 0 : Serial.println("4 keys R CT"); break; case 1 : Serial.println("8 keys R CT CT CT"); break; case 2 : Serial.println("8 keys R Ⅲ Ⅴ R or Ⅶ "); break; } if( !chord_progression.getIsPlus() ){ chord_progression.setIsPlus(true); } else { chord_progression.setIsPlus(false); } }else{ if( chord_progression.getTrack() + 5 <= ( HOW_MANY_SONGS -1 ) ){ chord_progression.setTrack( chord_progression.getTrack() + 5 ); }else{} chord_progression.song_init(); interval.set_intevals(&chord_progression); } break; } } void handleReleasedSwitches( ButtonID button_id, bool calculation_type ){ DIYKeyID diy = diy_key_id_array[ button_id ]; switch_class.setIsPressredFirst( diy, 0xFF ); switch_class.setIsSwitchOn( button_id, false ); switch_class.releasedkey( button_id, calculation_type, diy, &interval, &chord_progression ); } void released(ButtonID button_id) { //Serial.print("Released"); Serial.println(button_id); if( ( KEY_L1_A <= button_id && button_id <= KEY_L27_B ) || ( KEY_R1_A <= button_id && button_id <= KEY_R27_B ) ){ if( !( button_id % 2 ) ) handleReleasedSwitches( button_id, TYPE_A ); else handleReleasedSwitches( button_id, TYPE_B ); } } };//*/ MyButtonHandler handler; void setup() { decoder.setup(); button_input.setup(); Serial.begin(115200); Serial2.begin(31250); loop_0_7 = 0; Serial.println("hello world, SPRESENSE!"); isStart = true; chord_progression.song_init(); if( chord_progression.getChordChangingMode() ){ if( chord_progression.getKey_Layout() ){ chord_progression.setIsBasicBefore( false ); } else{ chord_progression.setIsBasicBefore( true ); } chord_progression.setKey_Layout(true); } else{ chord_progression.setKey_Layout( true ); } interval.set_intevals(&chord_progression);//*/ } void loop() { decoder.next(); if( 0 <= loop_0_7 && loop_0_7 <= 7 ){ delay(1); button_input.scan( &handler, &decoder ); }//*/ if(loop_0_7==7) loop_0_7=0; else loop_0_7++; } ```