Skip to content
Hans Lindetorp edited this page Sep 28, 2021 · 4 revisions

Like in film music, adaptive music often uses Motifs to play a certain phrase or sound triggered by an event in the game. In iMusic, these Motifs can be synchronised with other music, like a loop playing in the background. The Motifs are dependent on the current tempo and time signature used by the current loop. You can either restrict a Motif to be used only for a certain Arrangement or globally for all arrangements. A Motif has to have a "tag" for javascript to be able to trig it.

Please check Getting started to learn how to set tempo, time signatures and att loops.

i.e. add a Motif available for all sections:

<?xml version="1.0" encoding="UTF-8"?>
<imusic version="1.0" tempo="60" timeSign="4/4" audioPath="audio" suffix="mp3" loopLength="4">
  <motif tags="motif1" src="motif1"></motif>
  <arrangement src="loopA"></arrangement>
</imusic>

Play the Motif with a call from iMusic:

function myFunction(){
  iMusic.play("motif1");
}

i.e. add a Motif restricted to be used only when section "A" is playing Place it INSIDE the <arrangement>-element:

<?xml version="1.0" encoding="UTF-8"?>
<imusic version="1.0" tempo="60" timeSign="4/4" audioPath="audio" suffix="mp3" loopLength="4">
	
  <arrangement select-group="section" select-value="A" selected="true">
    <track src="loopA"></track>
    <motif tags="motif1" src="motif1A"></motif>
  </arrangement>
	
  <arrangement select-group="section" select-value="B">
    <track src="loopB"></track>
    <motif tags="motif1" src="motif1B"></motif>
  </arrangement>

</imusic>

To make Motif use different files selected randomly, just add a list with different <source>-elements:

<motif tags="motif1">
  <option src="motif1a"></option>
  <option src="motif1b"></option>
</motif>

Read more about random functions: Options

Read more about selecting different files with selection-groups or variables: Selecting

Motifs are by default played on the next beat in the music. If you want to change that, you set the quantize property:

<!-- to eight note -->
<motif quantize="1/8" class="motif1" src="motif1B"></motif>

<!-- to bar -->
<motif quantize="bar" class="motif1" src="motif1B"></motif>

A motif can also be used to play sound effects that are not quantized to the beat in the music layer. Then just set quantize to "off":

<!-- no quantize -->
<motif quantize="off" class="sfx" src="sfx.mp3"></motif>
Clone this wiki locally