Skip to content

Commit

Permalink
Module parameter change now has an auto glide utility
Browse files Browse the repository at this point in the history
  • Loading branch information
igorski committed Nov 19, 2017
1 parent 6d07444 commit d8f3435
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ src/js/handlebars/*
*.log
*.DS_Store
Thumbs.db
package-lock.json
3 changes: 3 additions & 0 deletions src/assets/css/patternEditor.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
&.moduleParams {
background-image: url('../images/icon-module-params.png');
}
&.moduleGlide {
background-image: url('../images/icon-module-glide.png');
}

&:hover {
background-color: @color-1;
Expand Down
Binary file added src/assets/images/icon-module-glide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 28 additions & 4 deletions src/js/controller/PatternEditorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
*/
"use strict";

const Pubsub = require( "pubsub-js" );
const Messages = require( "../definitions/Messages" );
const DOM = require( "zjslib" ).DOM;
const Pubsub = require( "pubsub-js" );
const Copy = require( "../i18n/Copy" );
const Messages = require( "../definitions/Messages" );
const EventUtil = require( "../utils/EventUtil" );
const DOM = require( "zjslib" ).DOM;

/* private properties */

let container, efflux, indiceContainer, controlContainer;
let stepAmount = 0, activeIndex = 0, patternIndices, rafPending = false, controlOffsetY = 0, lastWindowScrollY = 0;
let stepAmount = 0, rafPending = false, controlOffsetY = 0, lastWindowScrollY = 0;

module.exports =
{
Expand All @@ -52,6 +54,7 @@ module.exports =
container.querySelector( ".addOff" ).addEventListener ( "click", handleNoteOffClick );
container.querySelector( ".removeNote" ).addEventListener ( "click", handleNoteDeleteClick );
container.querySelector( ".moduleParams" ).addEventListener( "click", handleModuleParamsClick );
container.querySelector( ".moduleGlide" ).addEventListener( "click", handleModuleGlideClick );

// setup messaging system
[
Expand Down Expand Up @@ -146,6 +149,27 @@ function handleModuleParamsClick( aEvent )
Pubsub.publish( Messages.OPEN_MODULE_PARAM_PANEL );
}

function handleModuleGlideClick( aEvent )
{
const patternIndex = efflux.EditorModel.activePattern;
const channelIndex = efflux.EditorModel.activeInstrument;
const channelEvents = efflux.activeSong.patterns[ patternIndex ].channels[ channelIndex ];
const event = EventUtil.getFirstEventBeforeStep( channelEvents, efflux.EditorModel.activeStep );
let success = false;

if ( event ) {
const eventIndex = channelEvents.indexOf( event );
success = EventUtil.glideModuleParams(
efflux.activeSong, patternIndex, channelIndex, eventIndex, efflux.eventList
);
}

if ( success )
Pubsub.publish( Messages.REFRESH_PATTERN_VIEW );
else
Pubsub.publish( Messages.SHOW_ERROR, Copy.get( "ERROR_PARAM_GLIDE" ));
}

function updateStepAmount( amount )
{
stepAmount = amount;
Expand Down
2 changes: 2 additions & 0 deletions src/js/i18n/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const EN =
ERROR_NO_INS_NAME : `Please enter a name for the instrument preset`,
ERROR_INSTRUMENT_IMPORT : `Could not import instruments, file was possible not a valid ` +
`${Config.INSTRUMENT_FILE_EXTENSION} file, or made by an incompatible version of Efflux`,
ERROR_PARAM_GLIDE : `Could not automate module parameter glide. Define at least a start and end value for a
specific module`,
SUCCESS_TITLE : `Operation completed`,
MIDI_ENABLED : `Listening to MIDI messages coming from {0}`,
MIDI_CONNECTED : `MIDI Connection established successfully`,
Expand Down
16 changes: 14 additions & 2 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,20 @@ const efflux = window.efflux =

// song data

activeSong : null, // create new empty song
eventList : new Array( Config.INSTRUMENT_AMOUNT )
/**
* this will reference the currently active Song
*
* @type {SONG}
*/
activeSong : null,

/**
* Each channel uses a LinkedList to quickly
* link all events to each other (@see SequencerController)
*
* Array.<LinkedList>
*/
eventList : new Array( Config.INSTRUMENT_AMOUNT )
};

// WebAudio API not supported ? halt application start
Expand Down
27 changes: 12 additions & 15 deletions src/js/utils/EventUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

const EventFactory = require( "../model/factory/EventFactory" );

module.exports =
const EventUtil = module.exports =
{
/**
* update the position properties of given AudioEvent
Expand Down Expand Up @@ -86,11 +86,10 @@ module.exports =
}
else {

// any event (with an action) beyond this point is
// any event beyond this point is
// the "next" event in the list for given event

if ( compareEvent && compareEvent.action > 0 ) {

if ( compareEvent ) {
insertedNode = list.addBefore( compareEvent, event );
updatePreviousEventLength( insertedNode, song.meta.tempo );
return insertedNode;
Expand Down Expand Up @@ -167,7 +166,7 @@ module.exports =
* given step in given channel event list
*
* @public
* @param {Array.<AUDIO_EVENT|null>} channelEvents
* @param {Array.<AUDIO_EVENT>} channelEvents
* @param {number} step
* @return {AUDIO_EVENT|null}
*/
Expand Down Expand Up @@ -205,7 +204,7 @@ module.exports =
let listNode = list.getNodeByData( firstEvent );
let compareNode;

if ( !listNode )
if ( !firstParam || !listNode )
return false;

while ( compareNode = listNode.next ) {
Expand All @@ -219,13 +218,10 @@ module.exports =
// if new event has a module parameter change for the
// same module, we have found our second event

if ( secondParam.module === firstParam.module ) {
if ( secondParam.module === firstParam.module )
break;
}
else {
secondParam = null;
// TODO: what do we want to do in this case ?
}
else
return false;
}
// keep iterating through the linked list
listNode = secondEvent;
Expand All @@ -245,12 +241,13 @@ module.exports =
let prevEvent = firstEvent;
const events = [];

const addOrUpdateEvent = ( evt, channel, eventIndex ) => {
const addOrUpdateEvent = ( evt, pattern, patternIndex, channel, eventIndex ) => {
if ( typeof evt !== "object" ) {
// event didn't exist... create it, insert into the channel and update LinkedList
evt = EventFactory.createAudioEvent( firstEvent.instrument );
channel[ eventIndex ] = evt;
list.addAfter( prevEvent, evt )
list.addAfter( prevEvent, evt );
EventUtil.setPosition( evt, pattern, patternIndex, eventIndex, song.meta.tempo );
}
evt.mp = {
module: firstEvent.mp.module,
Expand All @@ -274,7 +271,7 @@ module.exports =
break;
}
else if ( eventFound ) {
event = addOrUpdateEvent( event, channel, j );
event = addOrUpdateEvent( event, pattern, i, channel, j );
events.push( event );
prevEvent = event;
}
Expand Down
1 change: 1 addition & 0 deletions src/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<li class="addOff"></li>
<li class="removeNote"></li>
<li class="moduleParams"></li>
<li class="moduleGlide"></li>
</ul>
</section>
<section id="patternTrackList">
Expand Down

0 comments on commit d8f3435

Please sign in to comment.