Homemade midi keyboard on 10 microcircuits. Dynamic MIDI keyboard on PIC16F84

The keyboard is designed to connect to an external sound module or computer (if the appropriate interface is available) using the MIDI protocol - to record music into a sequencer program or live performance. The number of keys in the proposed version is 48, can be increased up to 64 without altering the circuit. Distinctive feature The proposed keyboard is sensitive to the force of impact on the key.

History of the device

Some time ago, in connection with the purchase of an apartment, I was forced to lose a chic instrument that served as a MIDI keyboard for me - it was the legendary YAMAHA DX-7. When the sadness subsided, the question arose in all its sharpness and ugliness: what to work on? It was at this moment that, through the efforts of my friend, a semi-assembled circuit on KR1816BE39 fell into my grasping little hands (in adversary this processor is called 8048). The scheme is simple both in assembly and in adjustment, and, most importantly, turned up under the arm in right time. I assembled the keyboard in the form of an 8x6 matrix using KR1533ID7 and KR1533KP7. Not without a fly in the ointment - two shortcomings of this scheme to death kill all its advantages: lack of sensitivity to the speed of pressing the keys (speakers) and the PITCH WEEL wheel. Well, I used to program on the Z-80 (and even made a working sequencer) and decided to shake the old days. Z-80 as a CPU, I resolutely dismissed as obsolete. In addition, I didn’t want to solder a lot, and I decided to take this very device on the KR1816BE39 as a basis, equipping it with another multiplexer for breaking (upper) key contacts. I found documentation (you won't believe it - in the library, the book "Design digital devices on single-chip microprocessors") into the KR1816BE39 assembler and scrawled the program ... And then it turned out that a friend's ROM programmer had died, and there was simply nothing to sew the program with ... From grief, I completely lost my mind and decided to rewrite the same algorithm for PIC. In half a day, the programmer (LUDIPIPO) was soldered, then a layout from the socket, KR1533ID7 and a pair of KR1533KP7, and the entire installation was done by MGTF without any seal. And the process started...

First, a non-dynamic version of the program was launched (I also give it for those whose keyboard has one contact per key). Then the dynamic version started. And then the idea to add buttons and an indicator ripened. The fact is that I had a WAVEBLASTER scarf lying around for a long time (a child wavetable synthesizer for very old sound systems). By connecting it to my creation, I got something that I can play (to the best of my ability and talent) without a computer, which is sometimes quite convenient. This determined the set of functions on the buttons - it can be useful when connected to sound modules during a “live” game. Button functions are easy to change by writing your own handlers and using my polling and indication procedures. The keyboard somehow assembled in an iron case turned out to be more convenient than the YAMAHA PSS (still full-sized keys, a pedal and, most importantly, a speaker!). In the midst of the creative process, a formidable desire arose to make a pure computer version of the MIDI keyboard - the indicator and buttons are optional, but the PITCH WEEL and MODULATION wheels are needed. I struggled with it for a while, but finally gave up and turned on the soldering iron again. The electronics are easy to assemble, the mechanics are a little more difficult, and I began to wrinkle my forehead over the wheel arrangement. On reflection, I decided to abandon the second wheel - anyway, I never twist them both at once, I usually write notes and pitch first, then add modulation. Not the last consideration was the halving of the volume of mechanical works so beloved by me. For the less lazy, I will explain below how to make two wheels almost without complicating the scheme. To still be able to write modulation, I decided to organize three wheel modes: pitch by 2 semitones, pitch by 1 semitone (conveniently), and modulation. You can switch all this with one button, and indicate the mode with a pair of LEDs. To simplify the scheme, I eliminated the rest of the buttons and indicators; all this is not necessary to work with modern sequencer programs.

The wheel, of course, must be put on the axis of the potentiometer, this is understandable, but what should it be connected to? The first thought was to use a single vibrator on a 555 timer. But the calculation showed that it would be difficult to achieve accuracy and stability in measuring the pulse duration when trying to provide an acceptable wheel polling rate, because the processor is mainly busy measuring the switching time of the keyboard contacts. Remained the way to use analog-to-digital converter(ADC). Since I used Pic16F84 without a built-in ADC, I remembered my engineering past (and my own factory) and made an ADC from several resistors with a comparator (and a piece of the program). It turned out simple, cheap and quite accurate.

I give both schemes - with buttons and with a wheel, as well as programs for them. If desired, both circuits can be easily combined by slightly changing the addresses of external devices, you just need to remember that the CHORUS (STEREO) mode uses pitch to get detuning and you need to either remove it or take care of transmitting pitch with detuning through the channels.

So - the actual keyboard

Device diagram

The first to appear was a non-dynamic version, insensitive to the force of a keystroke - to test the layout's performance.

I used the PIC16F84 as a processor for several reasons: this chip is affordable, cheap and easy to program, in addition, it was she who was at my fingertips. Attention: PIC16C84 is not suitable - it has only 36 cells of RAM and the program will not work. However, the wheel circuit uses fewer RAM cells and its program can be squeezed into the PIC16C84 by reducing a couple more cells, for example MIDCH (assigning a constant MIDI channel to all transmitted data).

The diagram of a dynamic keyboard with indication is shown below:

The circuit is largely traditional - it is difficult to invent a bicycle without pedals and wheels. J Port B works for transmission - the lower 7 bits output the key address in the matrix or data for external devices (indicator and wheel DAC). The most significant bit is used to output MIDI data in serial code - the conversion and output is done by software. So the crystal should be at 4 MHz if you don't want to rewrite the MIDI byte output procedure. The two least significant bits of port A work for reception - they receive signals from the multiplexers of the “released” and “pressed” key contacts, and the three most significant bits determine the address external device(through another decoder KR1533ID7). In the circuit with the wheel, I refused the decoder of the address of the external device to simplify the circuit and free up the high bit of the PA4 port for entering data from the comparator, so the addresses of the keyboard and buttons are different. When combining circuits, this microcircuit will have to be returned, to decrypt the address, use the port bits PA2 and PA3, and address 4 devices: keyboard, buttons, dynamic indication data register and dynamic indication familiarity register. The indication of wheel modes will have to be rewritten.

The scheme with the PITCH WEEL / MODULATION wheel looks like this:

For each key, one diode is placed for decoupling. Resistors at the inputs of multiplexers should not be more than 8k, otherwise glitches are possible due to mounting capacitance. Indicator - any with a common anode for 3 digits, if the outputs of the segments of each digit are output separately, the outputs of the segments of the same name must be combined - the indication is dynamic and the digits are lit in series. Any buttons, without fixing, the bounce of contacts is choked programmatically. The LEDs are installed near the buttons of the same name and indicate the activation of the corresponding modes, the "+" and "-" buttons do not have LEDs. The transistors on the indicator are any low-power high-frequency reverse conduction. Two KR1533IR23 registers are used to alternately latch the address and code of the current digit of the indicator (the LEDs are also grouped into two quasi-digits). I used a standard keyboard from Soviet electric organs for 48 keys (it was also produced separately as a START radio designer, and is quite widespread). To reduce the height of the keyboard and the thickness of the instrument, two of the six contact groups under each key are left, and all this is cut off and re-glued. In general, one switching group per key is enough, but it was more convenient to glue it this way. The busbars of the “released” and “pressed” contacts are 8 keys long. If desired, you can also use a keyboard, where instead of a switching group of contacts, two pairs of closing contacts are used - one pair closes at the beginning of the key movement, the other at the end (as on YAMAHA tools). In this case, the signal to PA0 must be supplied from the inverse output of the multiplexer (pin 6). Without changes in the scheme, you can use a keyboard with 64 keys (the standard is 61, i.e. 5 octaves). If necessary, the number of keys can be increased even up to 127; for this, one more decoder KR1533ID7 must be introduced into the circuit.

It is very important to rebuild the mechanics well - the upper contacts MUST be closed when the keys are released. If this is not done, the program considers such keys to be pressed and tries to process them, so pressing these keys again does not produce sound. In addition, the maximum number of simultaneously sounding notes is 10 (if someone has grown more fingers on their hands, this number is easy to change), and unreleased keys reduce this number. For the same reasons, the number of keys indicated in the keyboard polling procedure MUST match the number of real keys. The bounce of contacts is choked programmatically.

For the resistive matrix R-2R ADC, it is desirable to select resistors with an accuracy of 1–2%, and the absolute values ​​may be different, the ratio is important. However, it is not worth it to greatly increase the value, this will increase the conversion time due to the input capacitance of the comparator. I have used unmatched SMD resistors, although measurements have shown that in the same mounting strip, the resistors are usually matched to better than 1%. I am sure that the circuit will work with inaccurate resistors, but the linearity of the characteristic will deteriorate. The wheel itself is made from a handle from an old TV and has a spring on the axis of the potentiometer that returns it to the middle position. For the convenience of setting up the mechanics, when the power is turned on with the mode button pressed, a debugging program is activated that lights up the LED when the wheel is in the middle position, this allows you to fine-tune the zero position of the wheel on the potentiometer axis. If there is a need and desire to make a separate MODULATION wheel, it must be connected to a free comparator element (there are four of them), and the R-2R matrix for both wheels is common. To switch the outputs of comparators, it is better to use an additional microcircuit, and use PA2 as a control signal.

If desired, you can assemble a dynamic version of the keyboard without indication, buttons and the PITCH WEEL / MODULATION wheel - simply without assembling an unused part of the circuit. All changeable parameters will be set by default at power on…

You can power it all from anything, the current consumption depends on the specific indicator and does not exceed 100 mA. I have a 7805 stabilizer without a heatsink right on the board (it can be clearly seen in the photo). A small radiator is needed if more than 9v is applied to it. The comparator is powered by a voltage of 9 - 12 v, preferably stabilized. Yes, I used Soviet-made microcircuits from old stocks - there are a large number of their modern analogues, replacement is possible and even desirable - modern analogues have less consumption.

Program

The algorithm for processing pressed keys comes from the one proposed in the journal "Microprocessor Tools and Systems" No. 5 for 1986. It was this publication (or rather, an error in the proposed program) that prompted me to study assembler. Actually, only the idea was taken from there to record the number of each key pressed in a specially allocated area of ​​\u200b\u200bRAM (CHAN), so that when the keyboard is re-polled, the already processed key is not processed again. I have two RAM cells for each of the keys pressed (no more than 10 in total): the first contains the number of the pressed key, the second - its VELOCITY (pressing speed). I repeat - there are only 20 of these cells and the starting address is given by the name CHAN. A sign of a free pair is the set high bit of the first cell. The set high bit of the second cell means that NOTE ON has already been transmitted for this key and it does not need further processing.

I will not describe the entire program in detail, the source code is replete with comments and is quite accessible for a trained person. For the rest, I immediately give ready-made firmware in the Dinamic.hex and Pitchmod.hex files. I will explain only some non-obvious points. Well, first of all, about the dynamics: at the moment of opening the upper contacts of the key, its number is written to the first cell of the first free pair from the CHAN area, simultaneously resetting the sign of a free pair. The second location is initialized with VELOCITY = 127. The sensitivity of the keyboard is determined by the frequency of interrupts, since interrupt processing decrements the VELOCITY values ​​for all keys whose NOTE ON has not yet been transmitted. Interrupts are triggered by the built-in timer. At the moment of closing the lower contacts of the key in the corresponding CHAN cell, the sign of "transmission" is set and NOTE ON is transmitted with the current VELOCITY. To improve the sensitivity curve, the decrease in VELOCITY values ​​follows a logarithmic law: 1/16 of its part, reduced by 1, is subtracted from the current VELOCITY value. and the faster the key moves, the greater the VELOCITY at the moment the lower contacts of the key are closed and NOTE ON is transmitted. Interrupts also control dynamic indication, this is done to eliminate the flickering of the indicator.
Button functions: TRANSPOSE - all keys are converted to your favorite A-minor: range +/- 15 semitones. PRG assigns a timbre (instrument) to a given preset (UP1-UP5), and VOL its volume. The current parameter is displayed on the indicator and can be changed with the "+" and "-" buttons. TWIN displays a "double" timbre - one of the presets (UP1-UP5) and simultaneously the LOWER preset sound at the same time. STEREO outputs the sound of the current preset to the left and right stereo channels with a slight "detuning" ("chorus" effect). The SPLIT button is disabled. The SUSTAIN pedal is designed as one of the buttons, the capacitance of its wire should not be very large. The addresses of the button handlers are collected in a table at the beginning of the program; when changing the functions of the buttons, you can substitute your own.

The ADC of the wheel is half software, it works according to the algorithm of successive approximations, the R-2R matrix performs the digital-to-analogue conversion. First, the matrix R-2R is supplied with 1 in the most significant digit, and the comparator determines whether it is a lot or a little. If it is small, 1 remains in the most significant bit, if there is a lot - 0. Then the same thing happens with each next least significant bit (6 steps in total) and we get a six-bit number corresponding to the angle of rotation of the wheel. This accuracy seems to me sufficient, but one more bit can be added by increasing the matrix and the transformation program.

Design

As the actual keyboard, I used the Soviet-made Start constructor, now it’s perhaps easier to find an old inoperable Yamaha or Casio, this will also solve the problem of making the case - if, of course, the old instrument has it relatively intact ...

The printed circuit board was not developed - I considered it inappropriate to spend time on wiring and manufacturing the board for the manufacture of a single instance of the device, and the layout was made on the circuit board using MGTF jumpers. A cable from floppy drives from a computer with a corresponding connector on each side was used as a connector and cable to the keyboard - this makes it easier to assemble / disassemble the finished device.

In my case, the body was curved from thin sheet steel (which was at hand) - with wooden sides (like old Soviet instruments).

Well, in short, that's all. Creative success!

List of radio elements

Designation Type Denomination Quantity NoteScoreMy notepad
Scheme No. 1.
microcontrollerPIC16F841 To notepad
ChipCR1533ID71 To notepad
ChipKR1533KP71 To notepad
Linear Regulator

LM7805

1 To notepad
Diode

KD522A

64 To notepad
Capacitor22 pF2 To notepad
Capacitor0.1uF2 To notepad
100uF2 To notepad
Resistor

220 ohm

2 To notepad
Resistor

6.8 kOhm

8 To notepad
Quartz resonator4 MHz1 To notepad
Keypad 64 To notepad
Scheme No. 2.
microcontrollerPIC16F841 To notepad
ChipCR1533ID72 To notepad
ChipKR1533KP72 To notepad
ChipKR1533IR232 To notepad
Linear Regulator

LM7805

1 To notepad
bipolar transistor

KT315A

5 To notepad
Diode

KD522A

80 To notepad
Capacitor22 pF2 To notepad
Capacitor0.1uF2 To notepad
electrolytic capacitor100uF2 To notepad
Resistor

180 ohm

7 To notepad
Resistor

220 ohm

2 To notepad
Resistor

6.8 kOhm

16 To notepad
Resistor

8 kOhm

1 To notepad
Quartz resonator4 MHz1 To notepad
3 digit LED digital indicator, with common anodes. 1 To notepad
Light-emitting diodeRed12 To notepad
Key switch 64 To notepad
Button 16 To notepad
Scheme No. 3.
microcontrollerPIC16F841 To notepad
ChipCR1533ID71 To notepad
ChipKR1533KP72 To notepad
comparator

Basically, the article is designed for guitarists and others like them, since few people need a foot controller, turn on the additional clave, bind the keys and go. Although maybe for DJs such management is quite appropriate. But it works best for Guitar Rig and TH1. In general, today we will collect something similar to:

And so, first you need to collect the necessary parts. Here is a short list of them:

Frame. The first and most basic thing is required, it is difficult to find the right one. I bought a cue case for this case.
- USB keyboard, preferably not very ancient, because perhaps the wiring will not work.
- Keys (those that I picked up): PBS-16B (FEET), SPA-101B4 (DOPA), PBS-15B push ON (ON). All without fixation. You can buy in Chip and Deep.
- Wires. Lots of singles. I think it's best for this twisted pair. 2 meters behind the eyes. It's just uncomfortable to unwind.
- Well, I think almost everyone has a soldering iron who decided to assemble this device.
- Tools for making holes in the body. Whoever is much, you can at least use a self-tapping screw, and then edit with a knife, but again, I think everyone has a drill.

Well, let's get started. The first thing to do is to mark and drill holes in the case:

Now let's move on to the more harmful part of making our footswitch. We solder the wires in accordance with the diagram, do not forget to hang identification sheets with the numbers of the inputs at the entrance from the keyboard:

It should turn out something like this:

Now a very jewelry process will begin for soldering to the controller from the USB keyboard. I note that if you are lucky to buy / find / take away a keyboard with such a controller as in the diagram attached above, then you cannot do without a soldering station. You can attach the board to the case with almost any means at hand, liquid nails, self-tapping screws, superglue, silicone, and in general, if you don’t wake up hard, it will hold on, but it depends on the case, the twisted pair presses the board tightly.

We make cosmetic improvements, whoever wants to, solder the diode to the case from NUB LOCK "and ... Make a hole for the wire and re-stretch USB cable. Well, there, that's enough fantasy. Final result:

Phase 2. Setup software. I hope this for everyone who made this device will not become a problem. For Guitar Rig, everything is easier than ever, turn on NUM Lock, turn on the rig, open OPTIONS - CONTROLLER, press MENU, look for the necessary action, kick the Learn key and select the appropriate button on our controller. Then click on Add Controller and perform the same operations again. And so on until we type everything that is needed or the keys run out. You can also assign a key to almost any action in the 3rd rig, right-click on the object and click again on Learn.

And now, if there is an interest in setting up all this brainchild for Midi teams, then you will have to have a little more fun.
So we need software that binds keys to midi commands. And there is such a program, although I have not seen any analogues, since it is not necessary to treat greed. Called Virtual Midi Controller, the key action is configured in the C IN tab, installation - Setup - Next - Next. Here's the link .


A virtual MIDI cable is also installed with it, so you don’t have to do extra gestures. For the very lazy, I post the bank preset for the footswitch: bank - they should replace the file in the root of the program folder, by default C:\Program Files\Virtual Midi Controller\ , after exiting the VMC. For convenience, check the Run In Background checkbox in SETUP and click on the letter K in the main VMC window, after which the program will accept commands in minimized mode. Now, to exit the program, you need to eliminate it in the tray. And from now on, you will be able to control both Nuendo and Sonar from the footswitch. Well, of course, TH1 also grabs our clave through the midi.

Any questions, please contact...

Next planned projects:
- Shielding of the guitar.
- Do-it-yourself combo.

Good luck with your music...

  • Sound
  • As a child, I had a piano, so real, Soviet, 300 kilograms. I liked to strum on it, and after graduating from a music school, even play something. The piano is cool, authentic, but not at all practical. And in order to be absolutely right for the soul, you also need a drum kit, heels of lotions for an electric guitar, a clarinet, a sitar and sample loops ...

    Of course, now it is no longer necessary to make a garage studio out of an apartment for a stash of six salaries, it is enough to install a free music editor on a PC. But, it's all inconvenient.

    The PC keyboard is not at all like a keyboard instrument, everything is different here. Moreover, it is not suitable for teaching a child at all. It seems that there is no choice but to purchase a synthesizer. But my doubts still haunt me.

    What is a synthesizer? A large device, with a musical keyboard, which should take up decent space somewhere. Which has built-in acoustics, but I already have a receiver with speakers. Which has a bad PC built in, and I have a good PC.

    It turns out that for 40 thousand I buy what I already have in best quality except for the keyboard. This is just some kind of maximum irrational spending.

    In search of a separate keyboard, I came across such a class of devices as the USB MIDI Keyboard.
    It always seemed to me that MIDI is from the field of professional musical activity.
    But now everyone makes music on a PC, in any convenient place, which means that musicians need mobile musical keyboards that can easily fit in a backpack.

    A plan immediately formed in my head. We connect a MIDI keyboard to a home media center based on Raspberry Pi 3, where a software synthesizer is spinning, allowing anyone to perform their next masterpiece at any time. On such MIDI keyboards, as a rule, there is a set of controls and additional buttons, which are programmed for various effects or additional musical instruments. It looks and sounds very cool!

    There are larger and smaller devices, there are more expensive and a little cheaper. I chose the option for about 5 sput. It has two octaves, normal-sized keys, drum buttons, tuning knobs, everything a beginner electronic musician can dream of.

    I am not an expert in creating music on PC, so it was difficult to find ways to implement my idea. Information had to be collected bit by bit. The puzzle gradually began to take shape and it turned out to assemble a working solution, which I am sharing with you. Oddly enough, but in the standard distribution of Raspbian/Debian, everything you need was found, you didn’t even have to connect external repositories.

    Fluidsynth is used as a sequencer (an application that plays MIDI files).
    The MIDI keyboard is immediately detected via ALSA and is available for connection to the sequencer.
    To play the sounds of various instruments, open sample bases in the SoundFont2 format are used. Let's install it all first.

    sudo -s apt-get update apt-get -y install alsa-utils fluid-soundfont-gm fluidsynth
    Connect a MIDI keyboard to Raspberry and start the sequencer in server mode:

    Fluidsynth -i -s -a alsa -g 3 /usr/share/sounds/sf2/FluidR3_GM.sf2
    We execute the command:

    Aconnect -o
    As a result, we will see a list of available MIDI clients:

    Client 14: "Midi Through" 0 "Midi Through Port-0" client 20: "VMini" 0 "VMini MIDI 1" 1 "VMini MIDI 2" client 128: "FLUID Synth (1628)" 0 "Synth input port (1628) :0)"
    Here it is important for us to remember the numbers of the keyboard and sequencer clients in order to then connect them with the command:

    Connect 20:0 128:0
    Now we are all set to play the Yamaha Piano (this is the default instrument). Read the fluidsynth manual, there are many interesting commands there, for example, to change the instrument to drums or brass, set the amount of reverb or chorus.

    Let's make our software synthesizer convenient. In order not to manually connect the keyboard to the sequencer every time, we will write a simple demon that will do this automatically at startup.

    cat > /etc/init.d/fluidsynth<< EOF #!/bin/bash ### BEGIN INIT INFO # Provides: fluidsynth # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Fluidsynth deamon to play via MIDI-keyboard ### END INIT INFO startDaemon() { sleep 30s && fluidsynth -i -s -a alsa -g 3 --load-config=/home/osmc/midi-router >/var/log/fluidsynth & sleep 60s && aconnect 20:0 128:0 & ) stopDaemon() ( pkill -9 fluidsynth &> /dev/null ) restartDaemon() ( stopDaemon startDaemon ) case "$1" in start) startDaemon ; ; stop) stopDaemon ;; restart) restartDaemon ;; status) ;; *) startDaemon esac exit 0 EOF
    Register a daemon for autorun:

    Chmod 755 /etc/init.d/fluidsynth update-rc.d fluidsynth defaults
    Please note that now, at startup, the sequencer is given a configuration file (/home/osmc/midi-router) containing commands that turn our keyboard into a real synthesizer.

    Here's the thing. Each key and knob on the keyboard sends certain events, with its own number. As I understand it, there are no special standards here, so each manufacturer does what he wants. For example, I want the square keys to sound like drums, the rest of the keys to sound like piano, and the knobs to control volume, reverb, and chorus.

    So, I need to map the event codes from the keyboard to different instruments, and the codes from the knobs to the codes that the sequencer understands. In fluidsynth, this is done using router. These commands are contained in the configuration file.

    Here is an example of my config file, with comments on what it does.

    Cat > /home/osmc/midi-router<< EOF # загружаем стандартные инструменты и ударники, найденные где-то на просторах Сети load /usr/share/sounds/sf2/FluidR3_GM.sf2 load /home/osmc/241-Drums.SF2 # связываем инструмент каждый со своим каналом select 1 2 128 0 select 2 1 0 0 # по умолчанию звук идет на канал 0 # перенаправляем события с квадратных клавиш на канал с ударными router_begin note router_chan 0 0 0 1 router_par1 36 48 1 0 router_end # события с остальных клавиш перенаправляем на канал с пианино router_begin note router_chan 0 0 0 2 router_par1 0 35 1 0 router_end router_begin note router_chan 0 0 0 2 router_par1 49 255 1 0 router_end # события с ручек мэпим на события, которые понимает секвенсер, # полный их список есть в документации на сайте fluidsynth router_begin cc router_chan 0 0 0 2 router_par1 14 14 0 98 router_end router_begin cc router_chan 0 0 0 2 router_par1 15 15 0 11 router_end router_begin cc router_chan 0 0 0 2 router_par1 16 16 0 91 router_end router_begin cc router_chan 0 0 0 2 router_par1 17 17 0 93 router_end # выключаем громкость на канале 0, # иначе при нажатии на клавишу # разные инструменты будут звучать одновременнно cc 0 7 0 EOF
    To find out what codes your device generates, you need to use this utility:

    aseqdump -p 20:0
    It listens and prints events from the MIDI keyboard to the console. Press the button or turn the knob and you will see the event type, channel and code. You can program your keyboard the way you want, not the way the engineers who designed the particular synthesizer came up with. For which many thanks to the developers of fluidsynth, alsa, SoundFont2, Raspberry and V-Mini.

    By the way, this topic with DIY synthesizers is reflected in several inventions, I recommend it for study.

    I think that those who have tried to work with sound on a computer have probably heard of such devices as midi controllers. Yes, and many people who are far from creating music had the opportunity to see artists at performances with a variety of "twists" and "pressers" for a fabulous price. How can you get hold of such a useful thing without spending a dime? A decent option is a homemade MIDI keyboard.

    A small educational program on midi-controllers

    Midi-controller (from the English abbreviation "MIDI" - the designation of the interface used in programs) - a device that allows you to expand the capabilities of your computer in terms of midi-communication.

    What can these devices do?

    MIDI controllers allow you to interact both with the program for creating and recording music (sequencer, tracker, etc.), and switch software with external hardware modules. The latter refers to various types, consoles, mechanical mixers, touchpads.

    The main problem of this class of “gadgets”, for a novice musician, is their high price: the average cost of a full-fledged new MIDI keyboard instrument is 7 thousand. The amount, of course, is ridiculous if you work somewhere and earn good money. (After all, in Russia the salary per capita is 28 thousand, considering the working population of babies and pensioners).

    But if you, for example, are a student, then such a price tag will be “biting” for you. Because of this aspect, using a homemade MIDI keyboard becomes the optimal solution to the problem.

    What needs to be done so that you have a homemade midi keyboard?

    To begin with, a sequencer must be installed on your computer. (All the nuances will be considered using the example of the Fl Studio sequencer and the Vanilin MIDI Keyboard emulator program, one of the most popular in its class).

    1. You need to download and install Vanilin MIDI Keyboard. You can find the program on its official website.
    2. Let's say that you have already installed this (or similar) application, now return to the desktop - a shortcut should appear there. Use this shortcut to start the emulator and go to the settings.
    3. If the computer has a standard sound card built into the chipset, then after clicking on the “Device” menu item, you should see two sub-items: “MIDI Remapper” and “Software Sound Synthesizer”. Click on "MIDI Remapper".
    4. Close the program. In the lower right corner of the taskbar (somewhere near the clock), the program icon should appear already familiar to you.
    5. Start the sequencer. Select the options menu (“Options”) and click on the MIDI settings sub-item (“MIDI settings”)
    6. In the MIDI output row ("Output") select "MIDI Remapper"

    After you have redone all these simple actions, create some kind of tool and try to click on any keyboard. If you did everything right and did not set up an empty (or muted) instrument, then you should hear a sound.

    That's it, now you have a real keyboard instrument in your hands! Now you can not only see and hear the sound, but also feel the touch of the keys of your own piano.

    This is a simple MIDI keyboard layout designed to be used with a standard PC sound card with a MIDI/Game port. The keyboard is powered directly from the game port, no power supply needed.

    Midi Keyboard Schematic MKC64 v1.54



    Parts set


    Microcircuits: PIC16F84 or PIC16C84 controller. Decoder 74LS138 or analogue K555ID7.
    Quartz resonator: ZQ1 = 4 MHz.
    Capacitors: C1= 47mF; C2, C3=27pF; C4=0.1mF
    Resistors: R1,R2,R4 = 1 to 10kΩ; R3 = 270Ω to protect the MIDI output; R5 = 2k2
    Diodes: D1-D64 = KD522 (Any type of standard diodes)
    Connectors: DB15

    Firmware


    If you use the MKC1.4 firmware without the jmp1 jumper, then the start of the keys from the note DO (C) with the jumper from the note FA (F)
    If you use firmware MKC1.54, then jmp1 displays the soft button S1, which allows you to control some functions
    To control, you must press the S1 button, and while holding it, press one of the 16 left keys on the keyboard.

    Function Control Key Table:
    1 Change MIDI channel -1 (1..16)
    2 Change MIDI channel +1 (1..16)
    3 Octave down -1 (1..11)
    4 Octave up +1 (1..11)
    5 Start note -1
    6 Trigger note +1
    7 Speed ​​down -1 (1..127)
    8 Speed ​​boost +1 (1..127)
    9 All Notes On message Enable
    10 All Notes Off message Disable
    11 NoteOn (speed = 0)
    12 Note Off
    13 MIDI Program -1
    14 MIDI Program +1
    15 MIDI bank -1
    16 MIDI Bank +1