|
| 1 | +import org.barrelorgandiscovery.tools.streamstorage.* |
| 2 | +import org.barrelorgandiscovery.editableinstrument.* |
| 3 | +import org.barrelorgandiscovery.scale.* |
| 4 | +import org.barrelorgandiscovery.virtualbook.rendering.* |
| 5 | + |
| 6 | +import javax.sound.sampled.* |
| 7 | +import org.barrelorgandiscovery.instrument.sample.* |
| 8 | + |
| 9 | +import org.barrelorgandiscovery.tools.* |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +// conversion d'instrument OR1 en instruments APrint |
| 16 | + |
| 17 | +def folder = "/home/use/projets/2022-02_Orgue_Electronique/work/sons_latourniquette/2024-05-23_sons_nouvelle_version/Flutes_Bijou" |
| 18 | + |
| 19 | + |
| 20 | +start = 36 |
| 21 | +end = 98 |
| 22 | + |
| 23 | + |
| 24 | +def outputFolder = new File(folder).parentFile |
| 25 | +outputFolder.mkdirs() |
| 26 | + |
| 27 | +def ei = new EditableInstrument() |
| 28 | + |
| 29 | +PipeStopGroupList pipestopgrouplist = new PipeStopGroupList() |
| 30 | + |
| 31 | +trackList = (start..end).collect { |
| 32 | + print(MidiHelper.midiLibelle(it)) |
| 33 | + new NoteDef(it) |
| 34 | +} |
| 35 | + |
| 36 | +print(trackList.collect { it.getMidiNote() }) |
| 37 | + |
| 38 | +def s = new Scale("tourniquette",(double) trackList.size()*2.0 + 5.0*2 , 2.0 as double, 2.0 as double, 5.0 as double, trackList.size(), trackList as AbstractTrackDef[], |
| 39 | + pipestopgrouplist, /*double speed*/ 60.0 , new ConstraintList(), |
| 40 | + /*java.lang.String infos*/(String) null , /*java.lang.String state*/ (String) null , /*java.lang.String contact*/ null , |
| 41 | + /*VirtualBookRendering rendering*/ null as VirtualBookRendering, /*boolean preferredViewedInverted*/ true, /* boolean bookMovingRightToLeft */ false, |
| 42 | + /*java.util.Map<java.lang.String,java.lang.String> properties*/ null) |
| 43 | + |
| 44 | + |
| 45 | +ei.name = "Tourniquette - Flutes" |
| 46 | +ei.scale = s |
| 47 | + |
| 48 | +TARGET_FORMAT = new AudioFormat(44000.0f, 16, 1, true, false) |
| 49 | + |
| 50 | +ss = (start .. end).collect { |
| 51 | + |
| 52 | + |
| 53 | + // perhaps a conversion to be done ... OK Done !! |
| 54 | + |
| 55 | + println("note ${it}") |
| 56 | + fileWav = new File(folder, "DEFAULT_" + it + ".WAV" ) |
| 57 | + if (!fileWav.exists()) { |
| 58 | + throw new Exception("error in opening ${fileWav}") |
| 59 | + } |
| 60 | + wavStream = new FileInputStream(fileWav) |
| 61 | + AudioInputStream ais = AudioSystem.getAudioInputStream(new BufferedInputStream(wavStream)); |
| 62 | + |
| 63 | + println("convert wav ..."); //$NON-NLS-1$ |
| 64 | + AudioFormat f = ais.getFormat(); |
| 65 | + // System.out.println(Messages.getString("JPatchEditor.11") + f); //$NON-NLS-1$ |
| 66 | + |
| 67 | + AudioInputStream targetInputStream = AudioSystem.getAudioInputStream(TARGET_FORMAT, ais); |
| 68 | + |
| 69 | + |
| 70 | + File tempFile = File.createTempFile("tmp", "wav"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 71 | + println("temp : ${tempFile}") |
| 72 | + |
| 73 | + tempos = new FileOutputStream(tempFile) |
| 74 | + StreamsTools.copyStream(targetInputStream,tempos) |
| 75 | + tempos.close() |
| 76 | + |
| 77 | + |
| 78 | + // AudioSystem.write(targetInputStream, Type.WAVE, tempFile); |
| 79 | + |
| 80 | + s = new SoundSample("N_" + it, it, new ManagedAudioInputStream(tempFile, TARGET_FORMAT, tempFile.length())) |
| 81 | + |
| 82 | + return s |
| 83 | + |
| 84 | +} |
| 85 | +//setSampleMapping(java.lang.String pipeStopGroup, SoundSample sample, int first, int end) |
| 86 | + |
| 87 | +ss.each { |
| 88 | + println("ajout ${it.name}") |
| 89 | + ei.addSoundSample(it, "DEFAULT") |
| 90 | +} |
| 91 | + |
| 92 | +println("${ss}") |
| 93 | + |
| 94 | +ss.eachWithIndex { it, index -> |
| 95 | + println("ajout sample ${index}, ${it}, ${it.getMidiRootNote()}") |
| 96 | + ei.setSampleMapping("DEFAULT", it, it.getMidiRootNote() ,it.getMidiRootNote() ) |
| 97 | +} |
| 98 | + |
| 99 | +eis = new EditableInstrumentStorage() |
| 100 | +fos = new FileOutputStream(new File(outputFolder, "tourniquetteflutes2.instrumentbundle")) |
| 101 | +eis.save(ei, fos ) |
| 102 | +fos.close() |
| 103 | + |
0 commit comments