Skip to content
Byson94 edited this page Apr 11, 2025 · 42 revisions

Plugin Development Guide

Welcome to the plugin development guide for MSE (Music Sheet Editor)!

This guide will help you make your own plugins for MSE (Music Sheet Editor). This wiki contains the best practices, handy tips, and detailed examples ranging from simple setups to more advanced concepts.


Table of Contents


Plugin Structure

Each plugin should follow this folder structure:

my-plugin/
├── script.js         # Main plugin logic
├── README.md         # The readme file of your plugin
└── info.txt          # This file should contain the version of your plugin usually in a format like `{"version":1.0}`

Getting Started

  1. Create a new folder in your plugins/ directory.
  2. Add the required files (script.js, README.md and info.txt).
  3. Open your app, and open a project. Navigate to the 3 vertical dots on the top-right of the screen and click it and then click script. Copy-paste your script.js code into script textarea and close it. Now your plugin should be loaded into the tool.

loadplugins


Writing Your First Plugin

While writing your first plugin, you gotta make sure that you know GDJS (GDevelop JavaScript API) since this software is built using GDevelop.

Check out the GDJS docs here:

Even if you don't know much about the API, you should at least grasp the basics of JavaScript, HTML and CSS.


Types of Plugins

When you're making a plugin, it usually falls into one of these two categories:

  • Menu-Based Plugin
    Plugins that show up in the interface (like buttons or tools) and perform tasks when the user interacts with them.

  • Background Plugin
    These plugins run silently in the background and perform tasks automatically, like analyzing the chart or modifying data behind the scenes.

or maybe even a hybrid of both the categories but, you only have to know the above ones because both requires different approaches with the menu based plugin being the most hardest compared to the background based plugin.


Background Plugin

Let's start off with the Background Plugin since its the easier one to implement. It only runs in the background and performs a specific task when the conditions are met.

Here is an example of a background plugin made by Michael:

if(runtimeScene.getOnceTriggers().triggerOnce(1)){
    registerTxt('event_display',true,false,30)
    runtimeScene.createObject('event_display').setPosition(415,34)
    runtimeScene.getObjects('event_display')[0].setLayer('Layer')
}
runtimeScene.getObjects('music_container').forEach(obj=>{if(gdjs.RuntimeObject.collisionTest(obj,runtimeScene.getObjects('play_node')[0],true)){
    runtimeScene.getObjects('event_display')[0].setString(obj.getVariables().get('data').getAsString())
}})

see events plugin source code made by Michael

Let's understand this code piece by piece

The code is wrapped in a triggers once so that it wont execute repeatedly in a loop

Note: GDevelop executes the code in a loop so if we want something to only trigger once, wrap it in a trigger once as shown in the example.

So after making sure that it only executes once, we create a text input at the x position: 415, and y position: 34.

  • This is the text in which we will display the event name of the node.
runtimeScene.getObjects('music_container').forEach(obj=>{if(gdjs.RuntimeObject.collisionTest(obj,runtimeScene.getObjects('play_node')[0],true)){
    runtimeScene.getObjects('event_display')[0].setString(obj.getVariables().get('data').getAsString())
}})

This code first gets all object named music_container (the playhead) and then for each number of music_container object on the screen, we would check if any of them collides with the play_node object (the node), and if it collides then we would change the string value of the text that we created before to the name of the node.

If you are wondering what the names of specific objects are, then you can skip over to [Object Names](#object-names) to find it out

Menu Based Plugins

This is the more complex part. GDJS doesn't directly support creating sprites or objects in the screen other than texts and other minor things.

But we can make a menu by tricking GDJS into loading an [iframe](https://www.w3schools.com/TAGS/tag_iframe.asp) with HTML5 code by injecting HTML code into an iframe.

Here is a simple example:

document.addEventListener("keydown", function (event) {
  if (event.ctrlKey && event.shiftKey && event.key.toLowerCase() === "s") { // add a custom keybind so that you can open your menu
    if (!document.getElementById("add-your-own-unqie-iframe-id")) {
      const iframe = document.createElement("iframe");
      iframe.id = "add-your-own-unqie-iframe-id";
      iframe.style.width = "340px"; // add your own width
      iframe.style.height = "280px"; // add your own height
      iframe.style.border = "2px solid #8A2BE2"; // style, you can choose your own
      iframe.style.borderRadius = "10px";
      iframe.style.position = "fixed";
      iframe.style.top = "50%";
      iframe.style.left = "50%";
      iframe.style.transform = "translate(-50%, -50%)";
      iframe.style.background = "#2D1B5A"; // style, you can choose your own
      iframe.style.zIndex = "1000";
      document.body.appendChild(iframe);

      iframe.srcdoc = `
                <html>
                <head>
                    <title>Example</title>
                </head>
                <style>
                   /* css style */
                </style>
                <body>
                    <script>
                       // your script
                    </script>
                </body>
                </html>
          `;
      /* const iframeHtml = `` // IF USING THIS PASTE THE HTML IN HERE.

      const blob = new Blob([iframeHtml], { type: "text/html" });
      iframe.src = URL.createObjectURL(blob); 

      This also works, you can use this if you dont want to use srcdoc.

      IF YOU NEEDS TO SAVE SOMETHING TO LOCALSTORAGE OR OTHER SAVING SYSTEMS, THEN USE SCRDOC
      IF YOU NEED TO POST/RECEIVE MESSAGES BETWEEN PARENT (THE MAIN DOCUMENT) AND THE CHILD (THE IFRAME)
      */
    }
  }
});

This example opens up a menu when we press ctrl+shift+s. If you press it, nothing will appear other than the iframe since the html is just bare bones and has no element or style.

      iframe.style.width = "340px"; // add your own width
      iframe.style.height = "280px"; // add your own height
      iframe.style.border = "2px solid #8A2BE2"; // style, you can choose your own
      iframe.style.borderRadius = "10px";
      iframe.style.position = "fixed";
      iframe.style.top = "50%";
      iframe.style.left = "50%";
      iframe.style.transform = "translate(-50%, -50%)";
      iframe.style.background = "#2D1B5A"; // style, you can choose your own
      iframe.style.zIndex = "1000";

These are the default styles that we applied to the iframe while creating it.

Clone this wiki locally