summaryrefslogtreecommitdiff
path: root/QMidiPlayer/doc/APIdoc.html
diff options
context:
space:
mode:
Diffstat (limited to 'QMidiPlayer/doc/APIdoc.html')
-rw-r--r--QMidiPlayer/doc/APIdoc.html156
1 files changed, 156 insertions, 0 deletions
diff --git a/QMidiPlayer/doc/APIdoc.html b/QMidiPlayer/doc/APIdoc.html
new file mode 100644
index 0000000..ea6bfd0
--- /dev/null
+++ b/QMidiPlayer/doc/APIdoc.html
@@ -0,0 +1,156 @@
+<h1 id="the-api-documentation-of-qmidiplayer-for-plugin-developers">The API documentation of QMidiPlayer for plugin developers</h1>
+<p><em>This manual is not yet complete. It's only a working draft for the always-changing plugin system in QMP.</em> <em>Handle with care.</em></p>
+<h1 id="overview">0. Overview</h1>
+<p>Plugin for QMidiPlayer is a dynamically-loaded library that exports the symbol <code>qmpPluginGetInterface</code> and <code>qmpPluginGetAPIRev</code>. Before starting developing your own plugin, make sure to have a look at the sample plugin in the &quot;sample-plugin&quot; folder.</p>
+<h1 id="qmidiplayer-plugin-sdk">1. &quot;QMidiPlayer Plugin SDK&quot;</h1>
+<p>SDK for developing QMidiPlayer plugins is merely the <code>qmpcorepublic.hpp</code> header found in the &quot;include&quot; directory in the source tree. It includes classes used by QMidiPlayer's internal plugin infrastructure.</p>
+<h1 id="basics-for-a-working-plugin">2. Basics for a working plugin</h1>
+<p>First of all, you should make your library distinct from other libraries that are not QMidiPlayer plugins. You can achive it by exporting the symbols <code>qmpPluginGetInterface</code> and <code>qmpPluginGetAPIRev</code>. Specifically, what you should do is to add the following snipplet to somewhere of your code:</p>
+<div class="sourceCode"><pre class="sourceCode c++"><code class="sourceCode cpp"><span class="at">extern</span> <span class="st">&quot;C&quot;</span>{
+ EXPORTSYM qmpPluginIntf* qmpPluginGetInterface(qmpPluginAPI* api)
+ <span class="co">//semicolon or implementation here.</span>
+ EXPORTSYM <span class="at">const</span> <span class="dt">char</span>* qmpPluginGetAPIRev()
+ {<span class="cf">return</span> QMP_PLUGIN_API_REV;}
+}</code></pre></div>
+<p>The <code>EXPORTSYM</code> macro tells the compiler to export the following symbol. <code>qmpPluginIntf</code> is the abstract class which every plugin class should derive from. The parameter api provides access to QMidiPlayer's plugin API, which should be stored for future use. <code>qmpPluginGetAPIRev</code> helps the core to determine whether the plugin is compatible with the API it exports.</p>
+<p>Next you should create your own plugin class which implements the abstract class <code>qmpPluginIntf</code>.</p>
+<h1 id="a-peek-into-the-class-qmppluginintf">3. A peek into the class <code>qmpPluginIntf</code></h1>
+<p>It has 6 public members: one default constructor, one default destructor and four methods:</p>
+<ul>
+<li><code>void init()</code><br />
+Called on start up if the plugin is loaded successfully and enabled.</li>
+<li><code>void deinit()</code><br />
+Called on shutdown if the plugin is enabled.</li>
+<li><code>const char* pluginGetName()</code><br />
+This function should return the display name of the plugin.</li>
+<li><code>const char* pluginGetVersion()</code><br />
+This function should return the version of the plugin, which will be shown in the plugin manager.</li>
+</ul>
+<p>Your plugin is expected to register handlers (hooks) and functionalities when init() is called by the host, and do clean-up jobs when deinit() is caled.</p>
+<p>Currently plugins can register handlers for these functionalities:</p>
+<ul>
+<li>Visualization (via <code>(un)registerVisualizationIntf</code>)</li>
+<li>MIDI File Reader (via <code>(un)registerFileReader</code>)</li>
+</ul>
+<p>...and can hooks into the following processes:</p>
+<ul>
+<li>Event reader, after an event is read or after the whole file reading process is completed (via <code>(un)registerEventReaderIntf</code> and <code>(un)registerFileReadFinishedHandlerIntf</code>)</li>
+<li>Event handler, when an event is going to be sent by the player (via <code>(un)registerEventHandlerIntf</code>)</li>
+</ul>
+<p>Functionalities has their own interfaces you need to implement(<code>qmpVisualizationIntf</code> and <code>IMidiFileReader</code>, respectively), while hooks uses the universal <code>IMidiCallBack</code> interface. Functionalities are discussed later.</p>
+<p>When you register a hook, you provide the core with a instance of your class that implements the <code>IMidiCallBack</code> interface and your <code>userdata</code> to be used when the core is calling the callback. When the callback is called, it will be fed with proper <code>callerdata</code> generated by the core and the <code>userdata</code> you provided. Type of <code>callerdata</code> varies by hooks. Event reader and handler hooks have <code>SEventCallBackData*</code> as their <code>callerdata</code> while file read finish hook doesn't provide <code>callerdata</code> (<code>NULL</code>).</p>
+<h1 id="functionalities">4. Functionalities</h1>
+<p>Plugins extend the host with extra functionalities. With hooks, handlers and the built-in core API, you can already do a lot of hacking. If that cannot make you satisfied, QMidiPlayer have several vacancies that are expected to be implemented by plugins. And with the introduction of the general functionality API, you can now virtually add anything to QMidiPlayer!</p>
+<h2 id="what-is-a-functionality">4.1 What is a functionality?</h2>
+<p>Have a look at the main window. By default there're three or four buttons at the bottom of it. These are functionalities. Functionalties go into two types: checkable and non-checkable. Checkable functionalities can be toggled on or off, while non-checkable functionalities have no such states. For non-checkable functionalities, only show() is called when the user invokes it. The user can arrange functionalities shown on the toolbar and the action menu to their needs.</p>
+<h2 id="visualization">4.2 Visualization</h2>
+<p>Visualization was once a feature of QMidiPlayer's core. But you can now write your own visualization with the Visualization interface(<code>qmpVisualizationIntf</code>). The methods in this interface should be self-explanatory.</p>
+<h2 id="midi-file-reader">4.3 MIDI File Reader</h2>
+<p>This is not strictly a &quot;functionality&quot;, because its interface IMidiFileReader does not inherit qmpFuncBaseIntf. When the user requests to open a file, the core tries to load the file with registered file readers and accepts the first valid result. Therefore you can implement your own file reader, which may even add eXtended Module support to QMidiPlayer!</p>
+<h2 id="midi-output-device">4.4 MIDI Output Device</h2>
+<p>This is not a functionality either. By implementing the interface qmpMidiOutDevice and registering it, you can add custom MIDI Devices in the built-in MIDI mapper.</p>
+<h1 id="generic-considerations">5. Generic Considerations</h1>
+<ol style="list-style-type: decimal">
+<li>If you implemented a API that returns a pointer to something, you can forget about the pointer after returning it. The core will free its memory after it is no longer used. You shouldn't extend the class pointed to because if you do so, the core will not be able to destruct it correctly. Examples include IMidiFileReader::readFile which returns a pointer to a CMidiFile class.</li>
+<li>However if you passed a pointer to the core through a function in qmpPluginAPI, you cannot forget about the pointer later. As these pointers are mostly polymorphic, the core cannot handle their destruction. You have to delete them yourself in the deinit() function of your plugin.</li>
+<li>Do not throw exceptions to the core. The core doesn't handle exceptions and they will crash the entire program. Use the return value to indicate failure of a procedure instead.</li>
+</ol>
+<h1 id="reference">6. Reference</h1>
+<p>Well, everything above is just nonsense compared to this one. The full reference of the API is here.</p>
+<h2 id="structures-classes">Structures &amp; Classes</h2>
+<h3 id="struct-sevent">struct <code>SEvent</code></h3>
+<p>Describes an MIDI event.</p>
+<ul>
+<li><code>uint32_t iid</code><br />
+internal id. Usually set to the size of the event pool when current event is read.</li>
+<li><code>uint32_t time</code><br />
+timestamp of the event in MIDI tick.</li>
+<li><code>uint32_t p1</code><br />
+parameter 1 for the midi event.</li>
+<li><code>uint32_t p2</code><br />
+parameter 2 for the midi event.</li>
+<li><code>uint8_t type</code><br />
+type of the event together with the channel this event goes to.</li>
+<li><code>std::string str</code><br />
+Contains the raw data for string-like events.</li>
+<li>default constructor: <code>SEvent()</code><br />
+sets everything to zero or empty.</li>
+<li>constructor with parameters: <code>SEvent(uint32_t _iid,uint32_t _t,char _tp,uint32_t _p1,uint32_t _p2,const char* s=NULL)</code><br />
+fills the event with the parameters given.</li>
+<li><code>friend bool operator &lt;(const SEvent&amp; a,const SEvent&amp; b)</code><br />
+compares events by their timestamps. Ties are broken by comparing precedence in file.</li>
+</ul>
+<h3 id="struct-seventcallbackdata">struct <code>SEventCallBackData</code></h3>
+<p>A stripped down version of SEvent that is used to pass event data in APIs.</p>
+<ul>
+<li><code>uint32_t time</code></li>
+<li><code>uint32_t type</code></li>
+<li><code>uint32_t p1</code></li>
+<li><code>uint32_t p2</code></li>
+</ul>
+<h3 id="class-cmiditrack">class <code>CMidiTrack</code></h3>
+<p>Describes a single MIDI track. A MIDI track consists of multiple MIDI events.</p>
+<ul>
+<li><code>std::vector&lt;SEvent&gt; eventList</code><br />
+Vector of SEvent's.</li>
+<li><code>void appendEvent(SEvent e)</code><br />
+Append an event to the end of the event list.</li>
+<li><code>SEvent&amp; operator[](size_t sub)</code><br />
+Get the reference to the contained event with the given index.</li>
+</ul>
+<h3 id="class-cmidifile">class <code>CMidiFile</code></h3>
+<p>Describes a MIDI file. A MIDI file consists of multiple MIDI tracks.</p>
+<ul>
+<li><code>bool valid</code><br />
+Is the MIDI file a valid one?</li>
+<li><code>char* title</code><br />
+Title of the MIDI file.</li>
+<li><code>char* copyright</code><br />
+Copyright information of the MIDI file.</li>
+<li><code>std::vector&lt;CMidiTrack&gt; tracks</code> Tracks in the MIDI file.</li>
+<li><code>uint32_t std</code><br />
+File standard of the MIDI file.
+<ul>
+<li>0: unknown</li>
+<li>1: GM Level 1</li>
+<li>2: GM Level 2</li>
+<li>3: GS</li>
+<li>4: XG</li>
+</ul></li>
+<li><code>uint32_t div</code><br />
+Ticks per quarter note. SMTPE format is not supported by QMidiPlayer.</li>
+<li><code>~CMidiFile()</code><br />
+Frees memory occupied by the title and copyright string.</li>
+</ul>
+<h3 id="class-imidicallback">class <code>IMidiCallBack</code></h3>
+<p>Generic callback function that can be used for hooking the core.</p>
+<ul>
+<li><code>IMidiCallBack()</code><br />
+Default empty constructor.</li>
+<li><code>virtual void callBack(void* callerdata,void* userdata)=0;</code><br />
+Abstract function of the callback. callerdata is filled by the caller and userdata is set to whatever you asked for when registering the callback.</li>
+<li><code>virtual ~IMidiCallBack()</code><br />
+Virtual empty destructor.</li>
+</ul>
+<h3 id="class-imidifilereader">class <code>IMidiFileReader</code></h3>
+<p>MIDI file reader interface. Use this to implement your file importer.</p>
+<ul>
+<li><code>IMidiFileReader()</code><br />
+Default empty constructor.</li>
+<li><code>virtual ~IMidiFileReader()</code><br />
+Virtual empty destructor.</li>
+<li><code>virtual CMidiFile* readFile(const char* fn)=0</code><br />
+Abstract function to be implemented by the plugin.<br />
+This function should read file from the given path (fn) and return a pointer to the resulting CMidiFile structure. You shoudn't handle the destruction of the resulting structure as the core will handle it.<br />
+Read 5.1 for more details.<br />
+After reading each event, you should call qmpPluginAPI::callEventReaderCB to invoke event reader callbacks and process their requests.<br />
+If a file not supported by the reader is provided, this function should return a CMidiFile* whose <code>valid</code> field is <code>false</code>.</li>
+<li><code>virtual void discardCurrentEvent()=0</code><br />
+Only called by event reader callbacks.<br />
+Expected behavior: Sets the discard flag for the last event you have read. If an event has its discard flag set, it shouldn't be pushed into its track.<br />
+discardCurrentEvent may be called multiple times by different event reader callbacks. In such case, there's still only one event discarded.</li>
+<li><code>virtual void commitEventChange(SEventCallBackData d)=0</code><br />
+Only called by event reader callbacks.<br />
+Expected behavior: modifies the last event you have read to the provided data.<br />
+commitEventChange may be called multiple times by different event reader callbacks. In such case, only the last modification to the current event counts.</li>
+</ul>