cmidi

cmidi
Download ALL MT5 librarys (391)
YouTube Video Thumbnail



Similar MetaTrader Tools

cmidi

Info

The cmidi is a Library for MetaTrader 5 that a class to control the midi device is located in the incmidi. mqh file.

Usage

This tool is typically used for enhancing chart analysis and decision making.

Platform

This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use cmidi

1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.

2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.

3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.

4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.

Frequently Asked Questions

Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.

Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.

Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.

What this tool does

A class to control the MIDI device is located in the incmidi.

Typical Use Case

This Library excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.

Description & Settings

Related: doubles comparer - another powerful library for MetaTrader 5 traders.

A class to control the MIDI device is located in the incmidi.mqh file. The example of its use is represented in the emidi.mq5 file.

Also recommended: high-performance json library for llms - similar library with strong performance on MetaTrader 5.


The order of using the cmidi class:

Connect a file with a class:

- Declare a class.

- Transfer music program using the setmusic(string & amusic[]) method.

- Enable playback using the play(bool asynch=true) method. If asynch is true, play is performed in a synchronous mode in the cycle with pauses using the sleep() function. If asynch is false, play is performed in a synchronous mode, and you can stop play using the stop() method. To work in a synchronous mode from the onchartevent() function of the expert advisor, the chartevent() method must be called.

- Call the stop() method upon completion of work. This is necessary for the MIDI device closing; otherwise, to rerun it, you should restart the terminal.

Music program

Music program is recorded in the string array. In one array element, a list of actions is written. Actions are written with a comma. First, a command, an equal sign, and a command value are written. The following commands are available:

- tick: time in milliseconds through which all the commands of one array element will be performed. It defines the tempo of the play.

- volume: the volume level, from 0 to 100.

- volumel: the left channel volume level, from 0 to 100.

- volumer: the right channel volume level, from 0 to 100.

- instrument: selection of the music instrument, from 0 to 127.

- notedn: press a key. Number 60 corresponds to the 'do' note of the main octave, 61 to 'c sharp', 62 to 're', etc.

- noteup: release a key. For some instruments, you cannot use release a key, as the sound fades away itself, and for specific keys, pressing is obligatory. It is possible to take chords, e.g., 'notedn=57, notedn=60, notedn=64'. Parallel play on several instruments is possible, e.g., 'instrument=1, notedn=60, instrument=123, notedn=60'. Different instruments' volume cannot be changed, and all play at the same volume. However, you can change the volume of different parts of the playing, for example:

The cmidi class methods:

- void chartevent(const int id, const long &lparam, const double &dparam, const string &sparam) - called from the function when using play in an asynchronous mode.

- void play(bool asynch=true) - enable play. If asynch is false, from the onchartevent function, the chartevent() method must be called.

- void stop() - stop play in an asynchronous play. Stop play and close the device.

- void setmusic(string & amusic[]) - send an array with a music program.

- void seteventid(ushort aid) - set a number for a custom event. This is necessary when using play in an asynchronous mode. It is not necessary to call it; the default value is 1.

You may also like: the master windows library - excellent alternative for library users on MetaTrader 5.

Source Code

#property copyright "robotfx"
#property link "https://robotfx.org"
#property version   "1.00"
#include <incmidi.mqh>
cmidi m;
int oninit(){
   string music1[]={
      "tick=150, volume=100, instrument=0",
      "notedn=62",
      "",

.......

Leave your opinion, ask a question, share some knowledge

Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.