Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
aEvent.preventDefault();
}
break;
case 83: // S
if ( hasOption ) {
Pubsub.publishSync( Messages.SAVE_SONG );
aEvent.preventDefault();
}
break;
case 86: // V
// paste current selection
if ( hasOption ) {
Pubsub.publishSync(
Messages.SAVE_STATE,
StateFactory.getAction( States.PASTE_SELECTION, {
efflux: efflux,
updateHandler: () => Pubsub.publishSync( Messages.REFRESH_PATTERN_VIEW )
})
);
}
break;
case 88: // X
// cut current selection
if ( hasOption )
{
Pubsub.publishSync(
function handleBroadcast( type, payload )
{
switch ( type )
{
case Messages.LOAD_SONG:
const song = ( typeof payload === "string" ) ? efflux.SongModel.getSongById( payload ) : payload;
if ( song && song.meta && song.patterns ) {
efflux.activeSong = ObjectUtil.clone( song );
efflux.EditorModel.reset();
efflux.EditorModel.amountOfSteps = song.patterns[ 0 ].steps;
SongUtil.resetPlayState( efflux.activeSong.patterns ); // ensures saved song hasn't got "frozen" events
Pubsub.publishSync( Messages.SONG_LOADED, song );
Pubsub.publishSync( Messages.CREATE_LINKED_LISTS );
efflux.StateModel.flush();
}
break;
case Messages.TRANSFORM_LEGACY_SONG:
if ( typeof payload === "object" )
SongValidator.transformLegacy( payload );
break;
case Messages.CREATE_LINKED_LISTS:
EventUtil.linkEvents( efflux.activeSong.patterns, efflux.eventList );
break;
case Messages.SAVE_STATE:
{
currentStep = 0;
// advance the measure if the Sequencer wasn't looping
if ( !looping && ++currentMeasure === totalMeasures )
{
// last measure reached, jump back to first
currentMeasure = 0;
// stop playing if we're recording and looping is disabled
if ( recording && !efflux.EditorModel.loopedRecording )
{
SequencerController.setPlaying( false );
Pubsub.publishSync( Messages.RECORDING_COMPLETE );
return;
}
}
SequencerController.setPosition( currentMeasure, nextNoteTime );
if ( recording )
{
// one bar metronome count in ?
if ( Metronome.countIn && !Metronome.countInComplete ) {
Metronome.enabled = Metronome.restore;
Metronome.countInComplete = true;
currentMeasure = 0; // now we're actually starting!
firstMeasureStartTime = audioContext.currentTime;
function handleMouseOver( aEvent )
{
Pubsub.publishSync( Messages.DISPLAY_HELP, "helpTopicSong" );
}
function handleDelayChange( aEvent ) {
const delay = model.instrumentRef.delay;
delay.enabled = ( Form.getSelectedOption( delayEnabledSelect ) === "true" );
delay.type = parseFloat( Form.getSelectedOption( delayTypeSelect ));
delay.time = parseFloat( delayTimeControl.value );
delay.feedback = parseFloat( delayFeedbackControl.value );
delay.cutoff = parseFloat( delayCutoffControl.value );
delay.offset = parseFloat( delayOffsetControl.value ) - 0.5;
Pubsub.publishSync( Messages.UPDATE_DELAY_SETTINGS, [ model.instrumentId, delay ]);
invalidatePresetName();
}
function switchPattern( newMeasure )
{
if ( editorModel.activePattern === newMeasure )
return;
currentMeasure = editorModel.activePattern = newMeasure;
Pubsub.publishSync( Messages.PATTERN_SWITCH, newMeasure );
const newSteps = efflux.activeSong.patterns[ newMeasure ].steps;
if ( editorModel.amountOfSteps !== newSteps ) {
editorModel.amountOfSteps = newSteps;
Pubsub.publish( Messages.PATTERN_STEPS_UPDATED, newSteps );
}
}
songs.forEach(( song ) =>
{
li = document.createElement( "li" );
li.setAttribute( "data-id", song.id );
li.innerHTML = "<span class="title">" + song.meta.title + ", by " + song.meta.author + "</span>" +
"<span class="date">" + Time.timestampToDate( song.meta.modified ) + "</span>" +
"<span class="delete">x</span>";
list.appendChild( li );
handler.addEventListener( li, "click", handleSongOpenClick );
handler.addEventListener( li.querySelector( ".delete" ), "click", handleSongDeleteClick );
});
Pubsub.publishSync( Messages.CLOSE_OVERLAYS, SongBrowserController );
Pubsub.publishSync( Messages.SHOW_BLIND );
container.classList.add( "active" );
}
function handlePatternClear( aEvent )
{
efflux.activeSong.patterns[ editorModel.activePattern ] = PatternFactory.createEmptyPattern( editorModel.amountOfSteps );
selectionModel.clearSelection();
Pubsub.publishSync( Messages.REFRESH_PATTERN_VIEW );
Pubsub.publishSync( Messages.CREATE_LINKED_LISTS );
}
songs.forEach(( song ) =>
{
li = document.createElement( "li" );
li.setAttribute( "data-id", song.id );
li.innerHTML = "<span class="title">" + song.meta.title + ", by " + song.meta.author + "</span>" +
"<span class="date">" + Time.timestampToDate( song.meta.modified ) + "</span>" +
"<span class="delete">x</span>";
list.appendChild( li );
handler.addEventListener( li, "click", handleSongOpenClick );
handler.addEventListener( li.querySelector( ".delete" ), "click", handleSongDeleteClick );
});
Pubsub.publishSync( Messages.CLOSE_OVERLAYS, SongBrowserController );
Pubsub.publishSync( Messages.SHOW_BLIND );
container.classList.add( "active" );
}