允许用户select 将电脑中的音乐文件加工成小品?

Allow user to select music files from computer into a processing sketch?

我正在创建一个音乐可视化工具。我停留在允许用户从他们的计算机上的音乐库上传音乐曲目并让可视化器响应他们选择的特定歌曲的节拍的部分。

我在 Processing 中使用了 minim 库,但是我必须在编码中加载文件名。我想要一种方法让用户单击一个按钮,该按钮将打开文件浏览器并允许他们 select 一首曲目,然后将该曲目输入播放器,播放器将播放该曲目并让可视化器响应节拍曲目。

我不是要密码;相反,我问的是逐步解决这个问题的方法。我坚持如何从计算机检索文件。我不太擅长编码,所以我正在网上查看图书馆和教程;我在这个主题上找到的视频只展示了如何将文本文件加载到草图而不是音乐文件中。

听起来您正在寻找 selectInput() 函数。

来自the reference

void setup() {
  selectInput("Select a file to process:", "fileSelected");
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
  }
}

Opens a platform-specific file chooser dialog to select a file for input. After the selection is made, the selected File will be passed to the 'callback' function. If the dialog is closed or canceled, null will be sent to the function, so that the program is not waiting for additional input. The callback is necessary because of how threading works.