Making a Game - Making Music - EP 25

by

Video Tutorial

Aims of this Tutorial

  • Fix a bug that I promised to fix months ago (sorry!).
  • Learn the ropes of music production with free and open source software.
  • Make a start on creating the combat music for the game.

Fixing the bug

The bug I am referring to is that you can send your current plan which is shorter than 5 seconds. This means that we need to pad this out and/or disable the end turn button until the criteria are met. We will only add this code to the client at the moment. In a later episode we will handle anti-cheat measures on the server. We will not be adding anti-cheat to the client because they are either invasive or ineffective (often both!) and I will not stand for such immoral decisions. We will instead focus on making the server reject invalid plans and thus there will be no problem.

The code to fix the bug is quite simple, we check that we are below the turn time and we go ahead and add on empty plan elements into our plans to fill up the time. Note that our plans have a method to get the current time in the current plan.

func fix_plans() -> void:
	if thrust_plan.current_time() < 5.0:
		var new_thrust_element : ThrustElement = ThrustElement.new()
		new_thrust_element.linear_thrust = Vector3.ZERO
		new_thrust_element.rotational_thrust = Vector3.ZERO
		new_thrust_element.time = 5.0 - thrust_plan.current_time()
 	if weapons_plan.current_time() < 5.0:
	    var new_weapons_element : WeaponsElement = WeaponsElement.new()
	    new_weapons_element.firing = false
	    new_weapons_element.time = 5.0 - weapons_plan.current_time()

This function is called at the beginning of the end turn. It assumes that a blank plan will have no thrust and will not be firing.

Setting up your Music Production Environment

You will need a few things to make music:

  • Digital Audio Workstation (DAW) - Ardour
  • Synthesizers - Geonkick, ZynAddSubFx (packaged as zyn-fusion on Arch)
  • Plugins - LSP plugins, Calf plugins
  • Sound Server - JACK 2

These are just my recommendation, you can do fine with other options. I will highly recommend that you do use JACK however, since it has many features that you will find very useful. To go with it, I recommend you use Cadence to easily set up bridges (eg for pulseaudio) and Carla to create connections between programs and plugins.

In this tutorial I will assume you are using these tools. If you are using different tools then the specifics may vary but the general scheme of things will be very similar.

Creating Music

Once you have created your first Ardour session, you may be intimidated by all of the buttons. But you need not worry, you only need a few of them to get started. 

Playback is fairly self explanatory since most media players have these buttons. The edit point is where things will appear when you paste something etc. Snapping allows you to get precision placement so you don't need to guess where the beat is. By default there is no snapping so set that to something like 1/4 or 1/8 beats for now. There are 3 modes that we care about right now:

  • Select Mode - Allows you to select and move blocks (like the one in red in the picture)
  • Region Mode - Allows you to select regions in the timeline, which is useful for copying tracks including their automation.
  • Edit Mode - Allows you to select, move and add notes. You can also click and drag within an empty track to make a new block.

Now let's create our first instrument. Press Ctrl+Shift+N to bring up the window to create a new track. Select MIDI track and pick zynaddsubfx (LV2) from the list of instruments. Click Add and Close and then double click the new zynaddsubfx red block on the left in the plugins panel. This will bring up a new window where you can pick a preset instrument to start with. You can then modify this instrument to your needs using the different panels on the left. Play around with this to your hearts content. 

If you have a slider where you like various positions, then we can start learning about learning. If you click the learn button in the top left and start moving the slider between positions you want to vary it and then click learn again, you will tell the plugin that you want to vary this parameter in the music. You can go to Macro Learn and rename Slot 1 to reflect what this does. To add more automation, simply press learn again and fiddle with a different knob and press learn once more.

Now we can head back into Ardour. We can go into edit mode and start placing down notes with the left mouse button. Press space to play your music and press L to loop. This will help you keep listening as you change different things to a section. Once you are happy with what you have, we can use the automation that we created earlier by clicking on the 'A' at the start of the track and selecting zynaddsubfx and picking slot 1. Then, change the mode of the new automation track to 'Play' and, in edit mode, create automation points that Ardour will interpolate between. This allows you to change the sound of your instrument throughout the song!

You can do this for all melodic instruments, but for percussion, while it is certainly possible (and perhaps desirable depending on what you are aiming for), it is superseded by Geonkick when it comes to percussion. This time, you will either need to provide samples of drum sounds or start off with the presets (see top bar). Again you can play around with different sounds in the kit by selecting them in the kit panel and going to the main panel and playing with the knobs and buttons.

Final Note

There may not be a written post next week depending on how music creation goes, since there will not be a lot to add when it comes to my personal choices for music creation, but I might give some general music theory tips. Also the matrix room for suggestions for these tutorials and for the game has been created and can be found here!