Search in sources :

Example 16 with Note

use of blue.soundObject.Note in project blue by kunstmusik.

the class CSDRender method generateCSDImpl.

@Override
protected CsdRenderResult generateCSDImpl(BlueData data, double startTime, double endTime, boolean isRealTime, boolean _usingAPI) {
    ProjectPluginManager.getInstance().preRender(data);
    StringChannelNameManager scnm = new StringChannelNameManager();
    ParameterNameManager pnm = new ParameterNameManager();
    ArrayList<StringChannel> stringChannels = getStringChannels(data.getArrangement(), scnm);
    ParameterHelper.clearCompilationVarNames(data);
    boolean usingAPI = isRealTime && _usingAPI;
    double renderStartTime = data.getRenderStartTime();
    // making copies to use for adding compileTime tables and instruments
    Tables tables = new Tables(data.getTableSet());
    ArrayList originalParameters;
    // if (usingAPI) {
    originalParameters = ParameterHelper.getAllParameters(data.getArrangement(), data.getMixer());
    // } else {
    // originalParameters = ParameterHelper.getActiveParameters(
    // data.getArrangement(), data.getMixer());
    // }
    assignParameterNames(originalParameters, pnm);
    Arrangement arrangement = new Arrangement(data.getArrangement());
    arrangement.clearUnusedInstrAssignments();
    boolean hasInstruments = arrangement.size() > 0;
    CompileData compileData = new CompileData(arrangement, tables, stringChannels, originalParameters, scnm, pnm);
    Mixer mixer = null;
    boolean mixerEnabled = data.getMixer().isEnabled();
    if (mixerEnabled) {
        mixer = new Mixer(data.getMixer());
        assignChannelIds(compileData, mixer);
    }
    NoteList generatedNotes;
    try {
        generatedNotes = data.getScore().generateForCSD(compileData, startTime, endTime);
    } catch (ScoreGenerationException ex) {
        throw new RuntimeException(ex);
    }
    compileData.setHandleParametersAndChannels(false);
    // assignParameterNames(originalParameters);
    // get parameters
    // ArrayList parameters;
    // if (usingAPI) {
    // parameters = ParameterHelper.getAllParameters(
    // arrangement, mixer);
    // } else {
    // parameters = ParameterHelper.getActiveParameters(
    // arrangement, mixer);
    // }
    GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
    OpcodeList udos = new OpcodeList(data.getOpcodeList());
    // add all UDO's from instruments and effects
    arrangement.generateUserDefinedOpcodes(udos);
    // adding all compile-time instruments from soundObjects to arrangement
    appendFtgenTableNumbers(globalOrcSco.getGlobalOrc(), tables);
    // generating ftables
    arrangement.generateFTables(tables);
    String ftables = tables.getTables();
    // Handle Render End Instrument and Note
    if (endTime > 0.0f && endTime > startTime) {
        Instrument instr = createRenderEndInstrument();
        int instrId = arrangement.addInstrument(instr);
        double endStartTime = endTime - startTime;
        try {
            Note renderEndNote = Note.createNote("i" + instrId + " " + endStartTime + " 0.1");
            generatedNotes.add(renderEndNote);
        } catch (NoteParseException e1) {
        }
    }
    Tempo tempo = data.getScore().getTempo();
    TempoMapper tempoMapper = null;
    if (tempo.isEnabled()) {
        tempoMapper = getTempoMapper(tempo);
        globalOrcSco.appendGlobalSco(getTempoScore(tempo, renderStartTime, endTime));
    } else {
        tempoMapper = getTempoMapper(globalOrcSco.getGlobalSco());
    }
    double totalDur = blue.utility.ScoreUtilities.getTotalDuration(generatedNotes);
    // double processingStart = blue.utility.ScoreUtilities.getProcessingStartTime(
    // tempPObj);
    // FIXME - figure out what to do about PROCESSING_START
    double processingStart = renderStartTime;
    System.out.println("<TOTAL_DUR> = " + totalDur);
    System.out.println("<RENDER_START> = " + renderStartTime);
    System.out.println("<PROCESSING_START> = " + processingStart);
    int nchnls = getNchnls(data, isRealTime);
    ArrayList<Instrument> alwaysOnInstruments = new ArrayList<>();
    // boolean generateMixer = mixerEnabled && (hasInstruments || mixer.hasSubChannelDependencies());
    arrangement.preGenerateOrchestra(compileData, mixer, nchnls, alwaysOnInstruments);
    String globalSco = globalOrcSco.getGlobalSco() + "\n";
    globalSco += arrangement.generateGlobalSco(compileData) + "\n";
    globalSco = preprocessSco(globalSco, totalDur, renderStartTime, processingStart, tempoMapper);
    double globalDur;
    try {
        globalDur = getGlobalDuration(globalSco);
    } catch (SoundObjectException ex) {
        throw new RuntimeException(ex);
    }
    if (globalDur < totalDur) {
        globalDur = totalDur;
    }
    System.out.println("Global Duration = " + globalDur);
    if (mixerEnabled) {
        globalDur += mixer.getExtraRenderTime();
    }
    for (Instrument instrument : alwaysOnInstruments) {
        String sourceId = compileData.getInstrSourceId(instrument);
        String noteStr;
        if (StringUtils.isNumeric(sourceId)) {
            int instrId = arrangement.addInstrumentAtEnd(instrument);
            noteStr = "i" + instrId + " 0 " + totalDur;
        } else {
            String instrId = sourceId + "_alwaysOn";
            arrangement.addInstrumentWithId(instrument, instrId, false);
            noteStr = "i \"" + instrId + "\" 0 " + totalDur;
        }
        try {
            Note n = Note.createNote(noteStr);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    if (mixerEnabled) {
        final String mixerId = "BlueMixer";
        // globalDur += mixer.getExtraRenderTime();
        clearUnusedMixerChannels(mixer, arrangement);
        globalOrcSco.appendGlobalOrc(mixer.getInitStatements(compileData, nchnls) + "\n");
        arrangement.addInstrumentWithId(mixer.getMixerInstrument(compileData, udos, nchnls), mixerId, false);
        try {
            Note n = Note.createNote("i \"BlueMixer\" 0 " + globalDur);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    handleParameters(originalParameters, stringChannels, globalOrcSco, generatedNotes, arrangement, startTime, startTime + globalDur, isRealTime, _usingAPI);
    if (isRealTime && !usingAPI) {
        Instrument instr = createBlueTimePointerInstrument();
        int instrId = arrangement.addInstrument(instr);
        try {
            Note n = Note.createNote("i" + instrId + " 0 " + globalDur);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    String tempGlobalOrc = compileData.getGlobalOrc();
    if (tempGlobalOrc != null && tempGlobalOrc.length() > 0) {
        globalOrcSco.appendGlobalOrc(tempGlobalOrc);
    }
    StrBuilder csd = new StrBuilder();
    appendProjectInfo(data, csd);
    csd.append("<CsoundSynthesizer>\n\n");
    appendCsInstruments(compileData, data, udos, arrangement, globalOrcSco, csd, mixer, isRealTime);
    appendCsScore(globalSco, ftables, generatedNotes, totalDur, csd);
    csd.append("</CsoundSynthesizer>");
    CsdRenderResult renderResult = new CsdRenderResult(csd.toString(), tempoMapper, originalParameters, stringChannels);
    return renderResult;
}
Also used : GlobalOrcSco(blue.GlobalOrcSco) NoteList(blue.soundObject.NoteList) NoteParseException(blue.soundObject.NoteParseException) Mixer(blue.mixer.Mixer) ArrayList(java.util.ArrayList) SoundObjectException(blue.soundObject.SoundObjectException) Tables(blue.Tables) CompileData(blue.CompileData) StrBuilder(org.apache.commons.lang3.text.StrBuilder) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Arrangement(blue.Arrangement) LinePoint(blue.components.lines.LinePoint) TempoMapper(blue.noteProcessor.TempoMapper) Tempo(blue.score.tempo.Tempo) ParameterNameManager(blue.automation.ParameterNameManager) ScoreGenerationException(blue.score.ScoreGenerationException) OpcodeList(blue.udo.OpcodeList) StringChannelNameManager(blue.orchestra.blueSynthBuilder.StringChannelNameManager) Note(blue.soundObject.Note) Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 17 with Note

use of blue.soundObject.Note in project blue by kunstmusik.

the class LineMultiplyProcessor method processNotes.

/*
     * (non-Javadoc)
     * 
     * @see blue.noteProcessor.NoteProcessor#processNotes(blue.soundObject.NoteList)
     */
@Override
public void processNotes(NoteList in) throws NoteProcessorException {
    Note temp;
    double oldVal = 0f;
    double multiplyVal = 0f;
    ValueTimeMapper tm = ValueTimeMapper.createValueTimeMapper(this.lineMultiplyString);
    if (tm == null) {
        throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.lineMultStringErr"), pfield);
    }
    for (int i = 0; i < in.size(); i++) {
        temp = in.get(i);
        try {
            oldVal = Double.parseDouble(temp.getPField(this.pfield));
            multiplyVal = tm.getValueForBeat(temp.getStartTime());
        } catch (NumberFormatException ex) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.pfieldNotDouble"), pfield);
        } catch (Exception ex) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.missingPfield"), pfield);
        }
        if (Double.isNaN(multiplyVal)) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.noteBeatErr"), pfield);
        }
        temp.setPField(Double.toString(oldVal * multiplyVal), this.pfield);
    }
}
Also used : Note(blue.soundObject.Note) NoteParseException(blue.soundObject.NoteParseException)

Example 18 with Note

use of blue.soundObject.Note in project blue by kunstmusik.

the class TimeWarpProcessor method processNotes.

/*
     * (non-Javadoc)
     * 
     * @see blue.noteProcessor.NoteProcessor#processNotes(blue.soundObject.NoteList)
     */
@Override
public void processNotes(NoteList in) throws NoteProcessorException {
    Note temp;
    TempoMapper tm = TempoMapper.createTempoMapper(this.timeWarpString);
    if (tm == null) {
        throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.tempoStringErr"));
    }
    double newStart, newEnd;
    for (int i = 0; i < in.size(); i++) {
        temp = in.get(i);
        try {
            newStart = tm.beatsToSeconds(temp.getStartTime());
            newEnd = tm.beatsToSeconds(temp.getStartTime() + temp.getSubjectiveDuration());
        } catch (Exception ex) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.timeWarp"));
        }
        temp.setStartTime(newStart);
        if (newEnd - newStart < 0) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.timeWarp"));
        }
        temp.setSubjectiveDuration(newEnd - newStart);
    }
}
Also used : Note(blue.soundObject.Note) NoteParseException(blue.soundObject.NoteParseException)

Example 19 with Note

use of blue.soundObject.Note in project blue by kunstmusik.

the class RandomAddProcessor method processNotes.

@Override
public final void processNotes(NoteList in) throws NoteProcessorException {
    Note temp;
    double range = max - min;
    double fieldVal = 0.0;
    Random r = seedUsed ? new Random(seed) : new Random();
    for (int i = 0; i < in.size(); i++) {
        temp = in.get(i);
        try {
            fieldVal = Double.parseDouble(temp.getPField(pfield));
        } catch (NumberFormatException ex) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.pfieldNotDouble"), pfield);
        } catch (Exception ex) {
            throw new NoteProcessorException(this, BlueSystem.getString("noteProcessorException.missingPfield"), pfield);
        }
        double randVal = (double) ((r.nextDouble() * range) + min);
        temp.setPField(Double.toString(fieldVal + randVal), pfield);
    }
}
Also used : Random(java.util.Random) Note(blue.soundObject.Note) NoteParseException(blue.soundObject.NoteParseException)

Example 20 with Note

use of blue.soundObject.Note in project blue by kunstmusik.

the class RetrogradeProcessor method processNotes.

@Override
public final void processNotes(NoteList in) {
    in.sort();
    Note temp;
    int size = in.size();
    temp = in.get(in.size() - 1);
    double totalTime = temp.getStartTime() + temp.getSubjectiveDuration();
    for (int i = 0; i < size; i++) {
        temp = in.get(i);
        // System.out.println("obj: " + temp.getObjectiveDuration() + "
        // subj: " + temp.getSubjectiveDuration());
        temp.setStartTime(totalTime - (temp.getStartTime() + temp.getSubjectiveDuration()));
    }
}
Also used : Note(blue.soundObject.Note)

Aggregations

Note (blue.soundObject.Note)30 NoteParseException (blue.soundObject.NoteParseException)14 NoteList (blue.soundObject.NoteList)11 Iterator (java.util.Iterator)2 Random (java.util.Random)2 Arrangement (blue.Arrangement)1 CompileData (blue.CompileData)1 GlobalOrcSco (blue.GlobalOrcSco)1 Tables (blue.Tables)1 ParameterNameManager (blue.automation.ParameterNameManager)1 LinePoint (blue.components.lines.LinePoint)1 Mixer (blue.mixer.Mixer)1 TempoMapper (blue.noteProcessor.TempoMapper)1 GenericInstrument (blue.orchestra.GenericInstrument)1 Instrument (blue.orchestra.Instrument)1 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)1 StringChannelNameManager (blue.orchestra.blueSynthBuilder.StringChannelNameManager)1 ScoreGenerationException (blue.score.ScoreGenerationException)1 ScoreObject (blue.score.ScoreObject)1 Tempo (blue.score.tempo.Tempo)1