Started working on a MIDI demonstration scene.
This commit is contained in:
parent
a99a387e52
commit
0d508db542
10 changed files with 1693 additions and 22 deletions
|
|
@ -67,6 +67,7 @@
|
|||
<Compile Include="Assets\Scripts\GameManager.cs" />
|
||||
<Compile Include="Assets\Scripts\LibPd2UnitySceneScripts\EnvelopeFollower.cs" />
|
||||
<Compile Include="Assets\Scripts\LibPdInstance.cs" />
|
||||
<Compile Include="Assets\Scripts\MidiSceneScripts\Button2Midi.cs" />
|
||||
<Compile Include="Assets\Scripts\PlayerMovement.cs" />
|
||||
<Compile Include="Assets\Scripts\SpatialisationSceneScripts\CircleMotion.cs" />
|
||||
<Compile Include="Assets\Scripts\Teleport.cs" />
|
||||
|
|
|
|||
1577
Assets/Scenes/MidiScene.unity
Normal file
1577
Assets/Scenes/MidiScene.unity
Normal file
File diff suppressed because it is too large
Load diff
7
Assets/Scenes/MidiScene.unity.meta
Normal file
7
Assets/Scenes/MidiScene.unity.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 34d87ee75336d8740ac7d748f153e629
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -81,28 +81,6 @@ public class IntIntEvent : UnityEvent<int, int> {}
|
|||
/// Along those lines, I modelled parts of this class after the C# bindings, so
|
||||
/// you will likely see some duplicated code.
|
||||
///
|
||||
/// Also, as it stands, this requires a small patch to z_libpd.c to allow us to
|
||||
/// install our own print hook (so we can pipe print messages to Unity's
|
||||
/// Console). Unfortunately, libpd requires the print hook to be set up before
|
||||
/// libpd_init() is called, and will not accept any changes after that.
|
||||
///
|
||||
/// This causes major problems with Unity, as we want to set the print hook when
|
||||
/// we start our game, and clear it when the game exits. However, because Unity
|
||||
/// keeps native dlls active as long as the editor is running, libpd_init()
|
||||
/// (being a one-time function) will effectively never get called again, and the
|
||||
/// print hook will remain set to the value set when we first ran our game from
|
||||
/// the editor. The result: if we try to run our game from the editor a second
|
||||
/// time, we crash the entire editor.
|
||||
///
|
||||
/// For this reason the repository for this code includes pre-built libpd
|
||||
/// binaries which include the print hook patch.
|
||||
///
|
||||
/// If you're building libpd from source yourself, you can get around this issue
|
||||
/// by adding the following line to the end of libpd_set_printhook() in
|
||||
/// z_libpd.c:
|
||||
///
|
||||
/// sys_printhook = libpd_printhook;
|
||||
///
|
||||
///
|
||||
/// Note: LibPdInstance is all implemented as a single file because I find
|
||||
/// single file libraries easier to integrate into my own projects. This may
|
||||
|
|
|
|||
8
Assets/Scripts/MidiSceneScripts.meta
Normal file
8
Assets/Scripts/MidiSceneScripts.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ba518842d32f7e42bcd55397b7699bd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/MidiSceneScripts/Button2Midi.cs
Normal file
51
Assets/Scripts/MidiSceneScripts/Button2Midi.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// Button2Midi.cs - Script to send a bang to a PD patch when the player enters
|
||||
// and leaves a collision volume.
|
||||
// -----------------------------------------------------------------------------
|
||||
// Copyright (c) 2020 Niall Moody
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
/// Script to send a random MIDI note to a PD patch when the player enters and
|
||||
/// leaves a collision volume.
|
||||
public class Button2Midi : MonoBehaviour {
|
||||
|
||||
/// The PD patch we're going to communicate with.
|
||||
public LibPdInstance pdPatch;
|
||||
|
||||
/// We need to store our random note so that we can send the corresponding
|
||||
/// note off message when the player exits the collision volume.
|
||||
private int note;
|
||||
|
||||
/// We send a bang when the player steps on the button (enters the collision
|
||||
/// volume).
|
||||
void OnTriggerEnter(Collider other) {
|
||||
note = 60 + Mathf.FloorToInt(Random.value * 12.0f);
|
||||
|
||||
pdPatch.SendMidiNoteOn(0, note, 127);
|
||||
}
|
||||
|
||||
/// We send a different bang when the player steps off the button (leaves
|
||||
/// the collision volume).
|
||||
void OnTriggerExit(Collider other) {
|
||||
pdPatch.SendMidiNoteOn(0, note, 0);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MidiSceneScripts/Button2Midi.cs.meta
Normal file
11
Assets/Scripts/MidiSceneScripts/Button2Midi.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 207c8a28d743b3e47bf8747003ca1c2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/StreamingAssets/PdAssets/MidiPatches.meta
Normal file
8
Assets/StreamingAssets/PdAssets/MidiPatches.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 39c36dfac37c5384da0b29cf84323fc8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#N canvas 735 157 356 522 10;
|
||||
#X obj 10 10 notein;
|
||||
#X obj 10 34 mtof;
|
||||
#X obj 10 122 osc~;
|
||||
#X obj 59 35 moses 1;
|
||||
#X obj 10 160 *~;
|
||||
#X obj 10 231 dac~;
|
||||
#X obj 59 103 vline~;
|
||||
#X msg 103 77 \$1 250;
|
||||
#X msg 59 76 0 500;
|
||||
#X obj 103 55 / 127;
|
||||
#X connect 0 0 1 0;
|
||||
#X connect 0 1 3 0;
|
||||
#X connect 1 0 2 0;
|
||||
#X connect 2 0 4 0;
|
||||
#X connect 3 0 8 0;
|
||||
#X connect 3 1 9 0;
|
||||
#X connect 4 0 5 0;
|
||||
#X connect 4 0 5 1;
|
||||
#X connect 6 0 4 1;
|
||||
#X connect 7 0 6 0;
|
||||
#X connect 8 0 6 0;
|
||||
#X connect 9 0 7 0;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a0507d186786af74f95f3fc37cdd6bb5
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue