52 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-06-15 15:18:06 -07:00
// midiSphere.js
//
// Script Type: Entity
// Created by James B. Pollack @imgntn on 9/21/2015
// Adapted by Burt
// Copyright 2015 High Fidelity, Inc.
//
// This script listens to MIDI and makes the ball change color.
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var _this;
function MidiSphere() {
_this = this;
2017-06-15 16:35:53 -07:00
this.clicked = false;
return;
2017-06-15 15:18:06 -07:00
}
2017-06-15 16:35:53 -07:00
2017-06-15 15:18:06 -07:00
MidiSphere.prototype = {
preload: function(entityID) {
this.entityID = entityID;
2017-06-15 16:35:53 -07:00
Midi.midiNote.connect(function(eventData) {
print("MidiSphere.noteReceived: "+JSON.stringify(eventData));
Entities.editEntity(entityID, { color: { red: 2*eventData.note, green: 2*eventData.note, blue: 2*eventData.note} });
});
print("MidiSphere.preload");
2017-06-15 15:18:06 -07:00
},
unload: function(entityID) {
2017-06-15 16:35:53 -07:00
print("MidiSphere.unload");
2017-06-15 15:18:06 -07:00
},
2017-06-15 16:35:53 -07:00
clickDownOnEntity: function(entityID, mouseEvent) {
print("MidiSphere.clickDownOnEntity");
if (this.clicked) {
Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
this.clicked = false;
Midi.playMidiNote(144, 64, 0);
} else {
Entities.editEntity(entityID, { color: { red: 255, green: 255, blue: 0} });
this.clicked = true;
Midi.playMidiNote(144, 64, 100);
}
}
2017-06-15 15:18:06 -07:00
};
// entity scripts should return a newly constructed object of our type
return new MidiSphere();
});