本文整理汇总了Java中javax.sound.midi.MidiSystem.write方法的典型用法代码示例。如果您正苦于以下问题:Java MidiSystem.write方法的具体用法?Java MidiSystem.write怎么用?Java MidiSystem.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e)
{
try
{
Tune t = m_tuneBookEditorPanel.getTuneEditArea().getTune();
if (t!=null)
{
JFileChooser chooser = new JFileChooser(lastDirectory);
int returnVal = chooser.showSaveDialog(m_parent);
File file = chooser.getSelectedFile();
if (file!=null)
{
MidiConverterAbstract conv = new BasicMidiConverter();
Sequence s = conv.toMidiSequence(t);
int[] types = MidiSystem.getMidiFileTypes(s);
if (types.length>0)
MidiSystem.write(s,types[0],file);
}
}
}
catch (IOException excpt)
{ excpt.printStackTrace(); }
}
示例2: testSampleFiles
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
@Test public void testSampleFiles() {
boolean writeFiles = true;
for (String file : MusicXmlScoreFileInputTest.getSampleFiles()) {
try {
val score = new MusicXmlScoreFileInput().read(jsePlatformUtils().openFile(file), file);
val sequence = MidiConverter.convertToSequence(
score, optionsForPlayback, new JseMidiSequenceWriter());
if (writeFiles) {
//try: write to file
new File("temp").mkdirs();
System.out.println("Converting: " + file);
MidiSystem.write(sequence.getSequence(), 1, new File("temp/" + file.replaceAll("/", "_") + ".mid"));
}
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to load file: " + file);
}
}
}
示例3: createSequenceInputStream
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Create a new InputStream containing a Sequence for testing.
*
* @return an InputStream containing a dummy Sequence, or null, if a problem
* occured while creating the InputStream
*/
private static InputStream createSequenceInputStream() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Sequence sequence = createSequence();
if (sequence == null) {
return null;
}
try {
MidiSystem.write(sequence, 0, baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return bais;
} catch (IOException e) {
return null;
}
}
示例4: setUp
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
protected void setUp() throws Exception
{
FrinikaSequence sequence = new FrinikaSequence(Sequence.PPQ, 128, 1);
int mpq = (int)(60000000 / tempo);
MetaMessage tempoMsg = new MetaMessage();
tempoMsg.setMessage(0x51,new byte[] {
(byte)(mpq>>16 & 0xff),
(byte)(mpq>>8 & 0xff),
(byte)(mpq & 0xff)
},3);
MidiEvent tempoEvent = new MidiEvent(tempoMsg,0);
sequence.getFrinikaTrackWrappers().get(0).add(tempoEvent);
ByteArrayOutputStream sequenceOutputStream = new ByteArrayOutputStream();
MidiSystem.write(sequence, 1, sequenceOutputStream);
Project20050227 project = new Project20050227();
project.setSequence(sequenceOutputStream.toByteArray());
SynthRack synthRack = new SynthRack(new VoiceServer() {
@Override
public void configureAudioOutput(JFrame frame) {
throw new UnsupportedOperationException("Not supported yet.");
}
});
MySampler sampler = new MySampler(synthRack);
synthRack.setSynth(1,sampler);
project.setSynthSettings(synthRack.getSynthSetup());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(project);
proj = ProjectContainer.loadProject(new ByteArrayInputStream(baos.toByteArray()));
}
示例5: store
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void store(OutputStream out) {
Sequence snapshot = storeSequence("Mixer");
try {
MidiSystem.write(snapshot, 1, out);
} catch ( IOException ioe ) {
ioe.printStackTrace();
System.err.println("Failed to create or write Snapshot file ");
}
}
示例6: createFastPrototypes
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* A hack to get a real FastShortMessage that can be cloned, e.g. Prototype
*/
private static void createFastPrototypes() {
try {
// create a sequence with a ShortMessage
Sequence sequence = new Sequence(Sequence.PPQ, 10);
Track track = sequence.createTrack();
track.add(new MidiEvent(new ShortMessage(), 0l));
// save the sequence
try {
File file = File.createTempFile("FSMhack", "mid");
MidiSystem.write(sequence, 0, file);
// load the sequence and get back the FastShortMessage
sequence = MidiSystem.getSequence(file);
track = sequence.getTracks()[0];
MidiMessage msg = null;
for ( int i = 0; i < track.size(); i++ ) {
msg = track.get(i).getMessage();
Class clazz = msg.getClass();
if ( fastShortPrototype == null &&
clazz.getCanonicalName().equals("com.sun.media.sound.FastShortMessage") ) {
fastShortPrototype = msg;
}
}
file.delete();
} catch ( IOException ioe ) {
}
} catch ( InvalidMidiDataException imde ) {
}
}
示例7: saveMidi
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Saves the MIDI data from a pattern into a file.
* @param pattern the pattern to save
* @param file the File to save the pattern to. Should include file extension, such as .mid
*/
public void saveMidi(Pattern pattern, File file) throws IOException
{
Sequence sequence = getSequence(pattern);
int[] writers = MidiSystem.getMidiFileTypes(sequence);
if (writers.length == 0) return;
MidiSystem.write(sequence, writers[0], file);
}
示例8: writeMIDI
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void writeMIDI(String fileName, EventList pedal) {
try {
MidiSystem.write(toMIDI(pedal), 1, new File(fileName));
} catch (Exception e) {
System.err.println("Error: Unable to write MIDI file " + fileName);
e.printStackTrace();
}
}
示例9: writeMidi
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Writes the given score as a MIDI file into the given stream.
*/
public static void writeMidi(Score score, OutputStream stream)
throws IOException {
Sequence sequence = MidiConverter.convertToSequence(score, optionsForFileExport,
new JseMidiSequenceWriter()).getSequence();
int type = MidiScoreFileOutput.getPreferredMidiType(sequence);
MidiSystem.write(sequence, type, new JseOutputStream(stream));
}
示例10: save
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void save(File file) throws IOException {
MidiSystem.write(sequence, 0, file);
}
示例11: saveAsMidiFile
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void saveAsMidiFile(File file) throws IOException {
MidiSystem.write(sequence, 1, file);
}
示例12: execute
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
@Override public void execute() {
FileChooser fileChooser = new FileChooser();
//use last document directory
File initDir = FileSettings.getLastDir();
if (initDir != null)
fileChooser.setInitialDirectory(initDir);
//add filters
SupportedFormats<?> supportedFormats = app().getSupportedFormats();
for (FileFormat<?> fileFormat : supportedFormats.getReadFormats()) {
addFilter(fileChooser, fileFormat);
}
//show the dialog
File file = fileChooser.showOpenDialog(ownerWindow);
if (file != null) {
log(remark("Dialog closed (OK), converting file \"" + file.getName() + "\""));
//save document directory
FileSettings.rememberDir(file);
//convert - TODO: show progress
String lastPath = file.getAbsolutePath();
List<Score> scores = pApp().loadMxlScores(lastPath, new AllFilter<>());
boolean useNumber = scores.size() > 1;
It<Score> scoresIt = new It<>(scores);
for (Score score : scoresIt) {
Sequence seq = MidiConverter.convertToSequence(
score, optionsForFileExport, new JseMidiSequenceWriter()).getSequence();
String newPath = lastPath;
String number = (useNumber ? ("-" + (scoresIt.getIndex() + 1)) : "");
if (newPath.toLowerCase().endsWith(".xml") || //TIDY: share code: FilenameUtils.numberFiles
newPath.toLowerCase().endsWith(".mxl")) {
newPath = newPath.substring(0, newPath.length() - 4);
}
newPath += (number + ".mid");
try {
MidiSystem.write(seq, 1, new File(newPath));
} catch (Exception ex) {
handle(warning(Voc.ErrorSavingFile));
}
}
}
else {
log(remark("Dialog closed (Cancel)"));
}
}
示例13: execute
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
@Override public void execute() {
DirectoryChooser dc = new DirectoryChooser();
//use last document directory
File initDir = FileSettings.getLastDir();
if (initDir != null)
dc.setInitialDirectory(initDir);
/* TODO - how to extend the DirectoryChooser in JavaFX?
//see http://stackoverflow.com/questions/25982945/javafx-filechooser-and-directorychooser-accessory-component
JCheckBox chkSubdir = new JCheckBox(Lang.get(Voc.IncludeSubdirectories), true);
JCheckBox chkCancel = new JCheckBox(Lang.get(Voc.CancelAtFirstError), false);
JPanel pnlOptions = new JPanel();
pnlOptions.setLayout(new BoxLayout(pnlOptions, BoxLayout.Y_AXIS));
pnlOptions.add(chkSubdir);
pnlOptions.add(chkCancel);
fc.setAccessory(pnlOptions); */
boolean subDirs = true; //TODO
boolean cancelOnFirstError = false; //TODO
File dir = dc.showDialog(ownerWindow);
if (dir != null) {
//remember directory
FileSettings.rememberDir(dir);
//start conversion - TODO: show progress
List<File> files = listFiles(dir, subDirs);
int countOK = 0;
int countFailed = 0;
for (File file : files) {
try {
//only process MusicXML files
FileType fileType = FileTypeReader.getFileType(new JseInputStream(file));
if (fileType != null) {
String filePath = file.getAbsolutePath();
List<Score> scores = pApp().loadMxlScores(filePath, new AllFilter<>());
if ((scores.size() == 0) /* TODO && chkCancel.isSelected() */) {
countFailed++;
break;
}
boolean useNumber = scores.size() > 1;
It<Score> scoresIt = new It<>(scores);
for (Score score : scoresIt) {
Sequence seq = MidiConverter.convertToSequence(
score, optionsForFileExport, new JseMidiSequenceWriter()).getSequence();
String number = (useNumber ? ("-" + (scoresIt.getIndex() + 1)) : "");
String newPath = filePath;
if (filePath.toLowerCase().endsWith(".xml") ||
filePath.toLowerCase().endsWith(".mxl")) {
newPath = newPath.substring(0, filePath.length() - 4);
}
newPath += (number + ".mid");
MidiSystem.write(seq, 1, new File(newPath));
countOK++;
}
}
} catch (IOException ex) {
countFailed++;
if (cancelOnFirstError) {
break;
}
}
}
app().showMessageDialog(
Lang.get(Voc.DirectoryConversionResult, "" + countOK, "" + countFailed));
}
}
示例14: write
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Actually write the data out to file.
*
* @throws IOException If the file cannot be written to.
*/
public void write() throws IOException {
MidiSystem.write(sequence, 1, outFile);
}
示例15: scrivi
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/** Scrive il brano in un file midi.
*
* @param path il percorso del file.
* @throws IOException se ci sono errori di I/O.
*/
public void scrivi( final String path ) throws IOException {
MidiSystem.write( sequence, 1, new File( path ) );
}