- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
JavaSound API 程序员指南中的图表似乎暗示(第 19-20 页)混合器原则上可以同时拥有数据线和端口。不过,我想知道是否有人真正见过这个配置?我看到的是,在相关的情况下,混合器成对出现,一个带有源/目标数据线,另一个带有相应的端口。
有没有人亲眼目睹过指南中暗示的配置,混音器同时具有端口和数据线(或者我是否误解了指南)?
最佳答案
我正在为我的网站开发此功能,网址为 pscode.org ,但还没有完全完成。无论如何,它都以小程序或应用程序的形式很好地概述了声音系统。
/*
<applet
code='MediaTypes'
width='800'
height='600'>
<param name='show' value='Sound|Sampled|Mixers|Primary Sound Driver'>
</applet>
*/
import javax.imageio.ImageIO;
import javax.sound.sampled.*;
import javax.sound.midi.*;
import java.awt.*;
import java.util.Arrays;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.*;
import javax.swing.event.*;
import javax.swing.text.Position;
public class MediaTypes extends JApplet {
JTable table;
boolean sortable = false;
JTree tree;
public void init() {
Runnable r = new Runnable() {
public void run() {
MediaTypes mediaTypes = new MediaTypes();
String show = "";
if (getParameter("show")!=null) {
show = getParameter("show");
}
JPanel p = new JPanel();
mediaTypes.createGui(p, show);
add(p);
validate();
}
};
SwingUtilities.invokeLater(r);
}
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
MediaTypes mediaTypes = new MediaTypes();
JPanel p = new JPanel();
mediaTypes.createGui(p);
JOptionPane.showMessageDialog(null,p);
}
};
SwingUtilities.invokeLater(r);
}
public Object[][] mergeArrays(String name1, Object[] data1, String name2, Object[] data2) {
Object[][] data = new Object[data1.length+data2.length][2];
for (int ii=0; ii<data1.length; ii++) {
data[ii][0] = name1;
data[ii][1] = data1[ii];
}
int offset = data1.length;
for (int ii=offset; ii<data.length; ii++) {
data[ii][0] = name2;
data[ii][1] = data2[ii-offset];
}
return data;
}
public void createGui(JPanel panel) {
createGui(panel, "");
}
public String getShortLineName(String name) {
String[] lineTypes = {
"Clip",
"SourceDataLine",
"TargetDataLine",
"Speaker",
"Microphone",
"Master Volume",
"Line In"
};
for (String shortName : lineTypes) {
if ( name.toLowerCase().replaceAll("_", " ").contains(shortName.toLowerCase() )) {
return shortName;
}
}
return name;
}
public void createGui(JPanel panel, String path) {
//DefaultMutableTreeNode selected = null;
panel.setLayout( new BorderLayout(5,5) );
final JLabel output = new JLabel("Select a tree leaf to see the details.");
panel.add(output, BorderLayout.SOUTH);
table = new JTable();
try {
table.setAutoCreateRowSorter(true);
sortable = true;
} catch (Throwable ignore) {
// 1.6+ functionality - not vital
}
JScrollPane tableScroll = new JScrollPane(table);
Dimension d = tableScroll.getPreferredSize();
d = new Dimension(450,d.height);
tableScroll.setPreferredSize(d);
panel.add( tableScroll, BorderLayout.CENTER );
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Media");
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
DefaultMutableTreeNode imageNode = new DefaultMutableTreeNode("Image");
rootNode.add(imageNode);
Object[][] data;
int offset;
String[] columnNames;
data = mergeArrays(
"Reader",
ImageIO.getReaderFileSuffixes(),
"Writer",
ImageIO.getWriterFileSuffixes() );
columnNames = new String[]{"Input/Output", "Image File Suffixes"};
MediaData md = new MediaData( "Suffixes", columnNames, data);
imageNode.add(new DefaultMutableTreeNode(md));
data = mergeArrays(
"Reader",
ImageIO.getReaderMIMETypes(),
"Writer",
ImageIO.getWriterMIMETypes() );
columnNames = new String[]{"Input/Output", "Image MIME Types"};
md = new MediaData( "MIME", columnNames, data);
imageNode.add(new DefaultMutableTreeNode(md));
DefaultMutableTreeNode soundNode = new DefaultMutableTreeNode("Sound");
rootNode.add(soundNode);
DefaultMutableTreeNode soundSampledNode = new DefaultMutableTreeNode("Sampled");
soundNode.add(soundSampledNode);
md = new MediaData("Suffixes", "Sound File Suffixes", AudioSystem.getAudioFileTypes());
soundSampledNode.add(new DefaultMutableTreeNode(md));
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
String[][] mixerData = new String[mixerInfo.length][4];
for (int ii=0; ii<mixerData.length; ii++) {
mixerData[ii][0] = mixerInfo[ii].getName();
mixerData[ii][1] = mixerInfo[ii].getVendor();
mixerData[ii][2] = mixerInfo[ii].getVersion();
mixerData[ii][3] = mixerInfo[ii].getDescription();
}
columnNames = new String[]{"Name", "Vendor", "Version", "Description"};
md = new MediaData("Mixers", columnNames, mixerData);
DefaultMutableTreeNode soundSampledMixersNode = new DefaultMutableTreeNode(md);
soundSampledNode.add(soundSampledMixersNode);
for (int ii=0; ii<mixerInfo.length; ii++) {
Mixer mixer = AudioSystem.getMixer(mixerInfo[ii]);
data = mergeArrays(
"Source",
mixer.getSourceLineInfo(),
"Target",
mixer.getTargetLineInfo() );
columnNames = new String[]{ "Input/Output", "Line Info" };
md = new MediaData(mixerInfo[ii].getName(), columnNames, data);
DefaultMutableTreeNode soundSampledMixerNode = new DefaultMutableTreeNode(md);
soundSampledMixersNode.add( soundSampledMixerNode );
//Mixer mixer = AudioSystem.getMixer(mixerInfo[ii]);
Line.Info[] source = mixer.getSourceLineInfo();
Line.Info[] target = mixer.getTargetLineInfo();
Line[] all = new Line[source.length + target.length];
try {
for (int jj=0; jj<source.length; jj++) {
all[jj] = AudioSystem.getLine(source[jj]);
}
for (int jj=source.length; jj<all.length; jj++) {
all[jj] = AudioSystem.getLine(target[jj-source.length]);
}
columnNames = new String[]{"Attribute", "Value"};
for (Line line : all) {
Control[] controls = line.getControls();
if (line instanceof DataLine) {
DataLine dataLine = (DataLine)line;
AudioFormat audioFormat = dataLine.getFormat();
data = new Object[7+controls.length][2];
data[0][0] = "Channels";
data[0][1] = new Integer(audioFormat.getChannels());
data[1][0] = "Encoding";
data[1][1] = audioFormat.getEncoding();
data[2][0] = "Frame Rate";
data[2][1] = new Float(audioFormat.getFrameRate());
data[3][0] = "Sample Rate";
data[3][1] = new Float(audioFormat.getSampleRate());
data[4][0] = "Sample Size (bits)";
data[4][1] = new Integer(audioFormat.getSampleSizeInBits());
data[5][0] = "Big Endian";
data[5][1] = new Boolean(audioFormat.isBigEndian());
data[6][0] = "Level";
data[6][1] = new Float(dataLine.getLevel());
} else if (line instanceof Port) {
Port port = (Port)line;
Port.Info portInfo = (Port.Info)port.getLineInfo();
data = new Object[2+controls.length][2];
data[0][0] = "Name";
data[0][1] = portInfo.getName();
data[1][0] = "Source";
data[1][1] = new Boolean(portInfo.isSource());
} else {
System.out.println( "?? " + line );
}
int start = data.length-controls.length;
for (int kk=start; kk<data.length; kk++) {
data[kk][0] = "Control";
int index = kk-start;
data[kk][1] = controls[index];
}
md = new MediaData(getShortLineName(line.getLineInfo().toString()), columnNames, data);
soundSampledMixerNode.add(new DefaultMutableTreeNode(md));
}
} catch(Exception e) {
e.printStackTrace();
}
}
int[] midiTypes = MidiSystem.getMidiFileTypes();
data = new Object[midiTypes.length][2];
for (int ii=0; ii<midiTypes.length; ii++) {
data[ii][0] = new Integer(midiTypes[ii]);
String description = "Unknown";
switch (midiTypes[ii]) {
case 0:
description = "Single Track";
break;
case 1:
description = "Multi Track";
break;
case 2:
description = "Multi Song";
}
data[ii][1] = description;
}
columnNames = new String[]{"Type", "Description"};
md = new MediaData("MIDI", columnNames, data);
DefaultMutableTreeNode soundMIDINode = new DefaultMutableTreeNode(md);
soundNode.add(soundMIDINode);
columnNames = new String[]{
"Attribute",
"Value"};
MidiDevice.Info[] midiDeviceInfo = MidiSystem.getMidiDeviceInfo() ;
for (int ii=0; ii<midiDeviceInfo.length; ii++) {
data = new Object[6][2];
data[0][0] = "Name";
data[0][1] = midiDeviceInfo[ii].getName();
data[1][0] = "Vendor";
data[1][1] = midiDeviceInfo[ii].getVendor();
data[2][0] = "Version";
String version = midiDeviceInfo[ii].getVersion();
data[2][1] = version.replaceAll("Version ", "");
data[3][0] = "Description";
data[3][1] = midiDeviceInfo[ii].getDescription();
data[4][0] = "Maximum Transmitters";
data[5][0] = "Maximum Receivers";
try {
MidiDevice midiDevice = MidiSystem.getMidiDevice(midiDeviceInfo[ii]);
Object valueTransmitter;
if (midiDevice.getMaxTransmitters()==AudioSystem.NOT_SPECIFIED) {
valueTransmitter = "Not specified";
} else {
valueTransmitter = new Integer(midiDevice.getMaxTransmitters());
}
Object valueReceiver;
if (midiDevice.getMaxReceivers()==AudioSystem.NOT_SPECIFIED) {
valueReceiver = "Not specified";
} else {
valueReceiver = new Integer(midiDevice.getMaxReceivers());
}
data[4][1] = valueTransmitter;
data[5][1] = valueReceiver;
} catch(MidiUnavailableException mue) {
data[4][1] = "Unknown";
data[5][1] = "Unknown";
}
md = new MediaData(midiDeviceInfo[ii].getName(), columnNames, data);
soundMIDINode.add( new DefaultMutableTreeNode(md) );
}
tree = new JTree(treeModel);
tree.setRootVisible(false);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener( new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
if (sortable) {
output.setText("Click table column headers to sort.");
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (nodeInfo instanceof MediaData) {
MediaData mediaData = (MediaData)nodeInfo;
table.setModel( new DefaultTableModel(
mediaData.getData(),
mediaData.getColumnNames()) );
}
}
} );
for (int ii=0; ii<tree.getRowCount(); ii++) {
tree.expandRow(ii);
}
String[] paths = path.split("\\|");
int row = 0;
TreePath treePath = null;
for (String prefix : paths) {
treePath = tree.getNextMatch( prefix, row, Position.Bias.Forward );
row = tree.getRowForPath(treePath);
}
panel.add(new JScrollPane(tree),BorderLayout.WEST);
tree.setSelectionPath(treePath);
tree.scrollRowToVisible(row);
}
}
class MediaData {
String name;
String[] columnNames;
Object[][] data;
MediaData(String name, String columnName, Object[] data) {
this.name = name;
columnNames = new String[1];
columnNames[0] = columnName;
this.data = new Object[data.length][1];
for (int ii=0; ii<data.length; ii++) {
this.data[ii][0] = data[ii];
}
}
MediaData(String name, String[] columnNames, Object[][] data) {
this.name = name;
this.columnNames = columnNames;
this.data = data;
}
public String toString() {
return name;
}
public String[] getColumnNames() {
return columnNames;
}
public Object[][] getData() {
return data;
}
}
关于具有端口和数据线的 JavaSound 混音器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5304001/
我之前让 dll 注入(inject)器变得简单,但我有 Windows 7,我用 C# 和 C++ 做了它,它工作得很好!但是现在当我在 Windows 8 中尝试相同的代码时,它似乎没有以正确的方
我正在尝试制作一个名为 core-splitter 的元素,该元素在 1.0 中已弃用,因为它在我们的项目中起着关键作用。 如果您不知道 core-splitter 的作用,我可以提供一个简短的描述。
我有几个不同的蜘蛛,想一次运行所有它们。基于 this和 this ,我可以在同一个进程中运行多个蜘蛛。但是,我不知道如何设计一个信号系统来在所有蜘蛛都完成后停止 react 器。 我试过了: cra
有没有办法在达到特定条件时停止扭曲 react 器。例如,如果一个变量被设置为某个值,那么 react 器应该停止吗? 最佳答案 理想情况下,您不会将变量设置为一个值并停止 react 器,而是调用
https://code.angularjs.org/1.0.0rc9/angular-1.0.0rc9.js 上面的链接定义了外部js文件,我不知道Angular-1.0.0rc9.js的注入(in
我正在尝试运行一个函数并将服务注入(inject)其中。我认为这可以使用 $injector 轻松完成.所以我尝试了以下(简化示例): angular.injector().invoke( [ "$q
在 google Guice 中,我可以使用函数 createInjector 创建基于多个模块的注入(inject)器。 因为我使用 GWT.create 在 GoogleGin 中实例化注入(in
我在 ASP.NET Core 1.1 解决方案中使用配置绑定(bind)。基本上,我在“ConfigureServices Startup”部分中有一些用于绑定(bind)的简单代码,如下所示: s
我在 Spring MVC 中设置 initBinder 时遇到一些问题。我有一个 ModelAttribute,它有一个有时会显示的字段。 public class Model { privat
我正在尝试通过jquery post发布knockoutjs View 模型 var $form = $('#barcodeTemplate form'); var data = ko.toJS(vm
如何为包含多态对象集合的复杂模型编写自定义模型绑定(bind)程序? 我有下一个模型结构: public class CustomAttributeValueViewModel { publi
您好,我正在尝试实现我在 this article 中找到的扩展方法对于简单的注入(inject)器,因为它不支持开箱即用的特定构造函数的注册。 根据这篇文章,我需要用一个假的委托(delegate)
你好,我想自动注册我的依赖项。 我现在拥有的是: public interface IRepository where T : class public interface IFolderReposi
我正在使用 Jasmine 测试一些 Angular.js 代码。为此,我需要一个 Angular 注入(inject)器: var injector = angular.injector(['ng'
我正在使用 Matlab 代码生成器。不可能包含代码风格指南。这就是为什么我正在寻找一个工具来“ reshape ”、重命名和重新格式化生成的代码,根据我的: 功能横幅约定 文件横幅约定 命名约定 等
这个问题在这里已经有了答案: Where and why do I have to put the "template" and "typename" keywords? (8 个答案) 关闭 8
我开发了一种工具,可以更改某些程序的外观。为此,我需要在某些进程中注入(inject)一个 dll。 现在我基本上使用这个 approach .问题通常是人们无法注入(inject) dll,因为他们
我想使用 swing、spring 和 hibernate 编写一个 java 应用程序。 我想使用数据绑定(bind)器用 bean 的值填充 gui,并且我还希望它反射(reflect) gui
我有这段代码,当两个蜘蛛完成后,程序仍在运行。 #!C:\Python27\python.exe from twisted.internet import reactor from scrapy.cr
要点是 Spring Batch (v2) 测试框架具有带有 @Autowired 注释的 JobLauncherTestUtils.setJob。我们的测试套件有多个 Job 类提供者。因为这个类不
我是一名优秀的程序员,十分优秀!