Jfugue编程概要

2023-11-18

转自:http://www.sudu.cn/info/html/edu/java/20060912/304274.html

JFugue是个用于音乐作曲的Java API。和其他的音乐API不同,他能够让你用数据字符串来指定音符、乐器、和弦,及其他音乐数据,而不必进行底层的MIDI操控。他和其他快速应用程式 研发环境类似,只不过是专门用于音乐编程的。在JFugue环境里,音乐编程目前相对简单,你不一定需要了解音乐理论知识;你能在Java应用程式正在运 行的时候用JFugue来演奏音乐,或把音乐保存为MIDI文件。

列表A向你显示了一个演奏音阶中乐符的简单JFugue应用程式(example1.java):

列表A
importorg.JFugue.*;
public class Example1
{
        public static void main(String[] args)
        {
                Player player = new Player();
                Pattern pattern = new Pattern("C D E F G A B");
                player.play(pattern);
                System.exit(0);
        }
}

音乐字符串

JFugue使用了“音乐字符串(Music String)”的概念??他用来指定音符、乐器变化,及演奏音乐所需要的其他数据。这个音乐字符串是个由字符组成的文字串,其中的每一组字符都代表着一条音乐命令。音乐命令能是下面几种类型中的一种:

  • Notes和chords??用来指定将要演奏的音符或和弦,及音值;
  • Tempo??用来指定乐曲的速度;
  • Voice??用来表示音符演奏的声部;
  • Instrument change??用来更换演奏音符的乐器或音色;
  • Controller messages??用来设置MIDI控制器事件,例如平衡等;
  • Variables??用来定义其他命令所使用的值。

目前就让我们来看看这些命令吧。

Notes你能用#和b字符分别表示一个音符是升半音还是降半音。除了用音符字母来指定音符之外,更有两种其他的方式来指定音符。一个是使用“音符值(note value)”,他是个表示音符的数值。MIDI有128个音符,编号是从0到127。第60号音符是Middle-C。要指定音符值,就要在一个方括号里加上数值,比如[60]。第二种方式是使用“打击乐器名(percussion name)”。在MIDI里,第10个声部(Voice 9,声部的编号从0开始)被保留给打击乐器。在这个声部,你能演奏多种不同的打击乐器声音,而且你能通过在方括号里指定打击乐器名来表示他们,例如[Hi_Bongo]。

OctaveMIDI能够演奏超过10个八度音阶的音符。要表示八度音阶,就要使用数字0到9。例如,有一个位于第6个八度音阶的A音符,他就要被表示为A6。如果你没有指定八度音阶,那么默认的音阶是Octave 5。

DurationDuration用来表示音符演奏的音值。如果你不输入 音值,那么默认的就是1/4个音符。下面这些值都是允许的:全音值(“w”)、半音值(“h”)、1/4音值(“q”)、1/8(“i”)、 1/16(“s”)、1/32(“t”)、1/64(“x”)和1/128音值(“n”)。你能通过在音值字符后面加上一个点(“.”)来表示一个点音 值。

英文原文:http://www.sudu.cn/info/html/edu/java/20060912/304274.html

JFugue is a Java API for music programming. Unlike other music APIs, it allows you to play data strings specifying notes, instruments, chords, and other musical data, without low-level MIDI manipulation.

It is similar to other rapid application development environments, only for music programming. In the JFugue environment, music programming is now relatively simple and a familiarity with music theory essentials is not required; you can use JFugue in your Java applications to play music while your application is running, or you can save music into MIDI files.

Listing A shows you a JFugue example of a simple application playing notes of a scale (example1.java):

Listing A
importorg.jfugue.*;

public class Example1
{
public static void main(String[] args)
{
Player player = new Player();
Pattern pattern = new Pattern("C D E F G A B");
player.play(pattern);
System.exit(0);
}
}

Music strings
JFugue employs the concept of a Music String – it is used to specify the notes, instrument changes, and other data required to play music. The Music String is a string of characters, where each group of characters represents a musical command. A musical command can be of one of the following types:

  • Notes and chords -- to specify a note or chord to play, and its duration;
  • Tempo -- specify the speed of the song;
  • Voice -- indicate the voice in which notes are to be played;
  • Instrument change -- Change the instrument, or patch, that is being used to play the notes;
  • Controller messages -- Set any of the MIDI controller events such as balance etc.;
  • Variables -- define a value for use by the other commands.

Let's have a closer look at these commands.

Notes: You can indicate that a note is sharp or flat by using the # and b characters, respectively. In addition to specifying a note using the note letter, there are two other ways to specify a note. One is to use the note value, which is a numerical value that indicates the note. MIDI has 128 notes, numbered 0 through 127. Note 60 is Middle-C. To specify a note value, enclose the value in square brackets; for example, [60]. The second way is to use a percussion name. In MIDI, the tenth voice (Voice 9, the voices begin with 0) is reserved for percussion sounds. There are a bunch of different percussion sounds you can play in that voice, and you can indicate them by giving the percussion name in brackets. For example,[Hi_Bongo].

Octave: MIDI is capable of playing notes than span 10 octaves. To indicate an octave, use the numbers 0 through 9. For example, here's an A note in the 6th octave: A6. If you don't specify the octave, the default is Octave 5.

Duration: The Duration tells for how long to play the note. If you don't enter a duration, the default is a quarter note. The following values are allowed: whole duration ("w"), half duration ("h"), quarter duration ("q"), eight ("i"), sixteenth ("s"), thirty-second ("t"), sixty-fourth ("x") and 1/128th duration ("n"). You can specify a dotted duration by following the duration character with a period ('.').

The duration of a dotted note is the original duration, plus half the duration. You can append durations to get a larger duration. For example, qh.would be a quarter note plus a dotted half note; wwww is four whole notes. In addition to specifying duration with a letter, you may also specify the duration as a decimal fraction. A quarter note would be 0.25, an eighth note would be 0.125, and so on. To represent a number as a decimal fraction use the / character followed by the fraction. For example, the following is an A note, 4th octave, half duration: A4/0.5.

Chords: Once you've specified the root (and, optionally, octave) of a chord, you can give its structure. All notes in a chord are played using the same instrument, in the same voice. There are many common chords structures recognized by JFugue, here are some of them: Major ("maj"), Minor ("min"), Major 7th ("maj7"), Minor 7th ("min7"), Diminished ("dim"), Augmented ("aug"). The chord indicator goes directly after the root and octave, and before the duration. For example, a C-major, 5th octave, quarter note would be C5majq.

There are two special characters that you may use to combine notes. The plus (+) character can be used to play multiple notes in at the same time (in harmony). The underscore (_) character can be used to play notes in order (in melody) when the melody is being played with a harmony. For example, "C5q+E5q+G5q" will play the same as "C5majq" chord.

Velocity: You can indicate how hard a note is struck, and how quickly the note is released. To indicate how hard a note is struck, set the attack velocity using the "a" indicator, followed by a value from 0 to 127. To indicate how quickly a note is released, set the decay velocity using the "d" indicator, followed by a value from 0 to 127. The default attack velocity and decay velocity for each note is 64. Incidentally, this is a standard default value for MIDI devices that do not support velocity. For example, "C5qa120d30" represents a Middle C, quarter duration, which is struck very strongly (120), and is released softly (30).

Tempo: You should specify the tempo of your song - how fast or slow the song should be played. The tempo value represents "Pulses Per Quarter", or PPQ, which is how many "pulses", or clock cycles, to give a quarter note. A smaller value will result in a faster song, and a larger number will result in a slower song. A good value to start with is 120; this is also the default if you do not specify a tempo. The command is a T, followed by a number from 0 to infinity. For example: T120.

Voice: The Voice command tells JFugue to play the following notes in the given MIDI voice (also known as a channel). You can think of a voice as a musical track. Voices give you the ability to play multiple melodies at the same time. If you're programming piano music, you can use one voice for the treble clef, and a second voice for the bass clef. If you're creating a symphonic piece, you could give each instrument its own track. The command is "V", followed by a number from 0 to 15. There are 16 voices, numbered 0 through 15. The tenth voice (or channel) is special -- it is the channel that plays the rhythm instruments. Notes played in this voice sound like drums, cymbals, woodblocks, and other percussion instruments. Since we're counting from 0, the tenth voice is Voice 9. When playing notes on Voice 9, you can use percussion names such as [Bass_Drum] or [Open_Hi_Hat] to represent the percussion instruments.

Instrument change: The Instrument Change command tells JFugue to play the following notes with the given MIDI instrument number or name. The command is an "I", followed by either a number from 0 to 127, or the name of an instrument enclosed in brackets, like "I9" or "I[Guitar]".

Patterns
A pattern is a collection of notes that comprise a musical statement. A pattern can represent an entire song, individual parts of a song, or snippets of frequently used music. Patterns may be created from other patterns, and the music in a pattern may be transformed in interesting and creative ways.

Patterns may be used to represent parts of a song. Suppose you're writing a standard rock or pop song. You might break your song into the following parts: Intro, Verse 1, Chorus, verse 2, Chorus, Verse 3, Chorus, Outro. To program this in JFugue, you can create the sections of music as patterns (Listing B, patterns.txt):

Listing B
Pattern intro = new Pattern("music string");
Pattern verse = new Pattern("music string");
Pattern chorus = new Pattern("music string");
Pattern breakdown = new Pattern("music string");
Pattern utro = new Pattern("music string");

Then, you can create the song using those sections (Listing C):

Listing C
Pattern song = new Pattern();
song.add(intro);
song.add(outro);

You can play the entire song by method:

player.play(song);

There are several additional features in JFugue which you can apply to a pattern.

Pattern Factories: A pattern factory gives you a pattern that you can use in your own songs.

Pattern Transformers: You can apply a transformation on any pattern. You can, for example, increase the interval between notes, add an echo to the notes, and many other transformations. The JFugue package comes with a few pattern transformers. They're all named XxxxPatternTransformer, where Xxxx indicates what they do -- for example, IntervalPatternTransformer changes the intervals between notes, DurationPatternTransformer changes the duration of notes, and ReversePatternTransformer reverses a pattern.

Pattern Tools: Patterns are a great way to manage sections of a musical statement. As you're using patterns, you may realize the need to perform. some calculation on a pattern. How long does this pattern play? What is the last voice that was used in this pattern? How many A notes are there in this pattern? Pattern tools are used to perform. calculations across a pattern. Like pattern transformers, they are parser listeners, and they work by parsing the pattern, and performing their calculations when the parser makes callbacks to the event methods.

Example
To give you an idea for further steps, this is one more example, ready to work. For further reading the JFugue site is the best option. This is the simplest example of a song player (Listing D, example2.java):

Listing D
import com.innix.jfugue.Player;
import com.innix.jfugue.Pattern;

public class Example2
{
public static void main(String[] args)
{
Player player = new Player();
Pattern pattern = new Pattern("T160 I[Cello] "+
"G3q G3qG3q Eb3q Bb3i G3q Eb3q Bb3i G3h");
player.play(song);
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/118838/viewspace-687551/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/118838/viewspace-687551/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jfugue编程概要 的相关文章

随机推荐

  • macOS 12 Monterey:一次全新的跨设备协作体验

    macOS 12 Monterey是苹果公司的一次重大突破 它打破了设备间的壁垒 将不同设备无缝地连接在一起 极大地提升了用户的工作效率和娱乐体验 Monterey带来了通用控制 AirPlay 捷径等新功能 以及一些实用的新小功能 安装
  • 本地项目放到服务器启动不了,spring boot在本地能启动,放服务器上就不行,

    写完代码 放到服务器上去发现启动不了 服务器的tomcat没有问题 因为上面已经有两个项目在跑 报错内容 百度过了 百度上都说是server api的问题 但是我没有引入这个包 被逼无奈才来这里请教的 java util concurren
  • 25_pre_content 阶段 mirror 模块

    文章目录 precontent 阶段的 mirror 模块 示例配置 precontent 阶段的 mirror 模块 作用 实时拷贝流量 处理请求时 生成子请求访问其他服务 对子请求的返回值不做处理 ngx http mirror mod
  • 调用接口登录禅道_Java调用禅道api接口查询以及创建任务(傻瓜式复制粘贴--旗舰版禅道页面调用)

    背景 系统需要调用禅道的接口进行工单的创建 并对工单进行附件上传等信息的操作 禅道接口为http接口 每次请求都需要带上zentaosid进行请求 由于专业版禅道升级为旗舰版禅道版本变更 请求的URL有所变化 变化最大为常量类配置 如下 实
  • Set集合

    目录 一 Set集合的特点 二 Set集合取值 三 常用实现类HashSet和TreeSet 四 Comparable和Comparator的使用 4 1 Comparable 4 2 Comparator 五 LinkedHashSet
  • HTML5本地存储

    1 背景 在HTML4 01中 想要在浏览器中存储用户的数据时 我们一般只能用Cookie来实现 不过Cookie有很多限制 大小限制 最大4KB 数量限制 每个站点只允许存储20个Cookie 如果想要存储更多Cookie 则要把旧的Co
  • 【数组中数字出现的次数-有限状态自动机】

    数组中数字出现的次数 一 有限状态自动机解法 二 一般解法 想必大家对数组中数字出现的次数的这种题并不少见 主要有三种 1 找出数组中只出现一次的数字 其他数字出现两次 2 找出数组中仅有的两个仅出现一次的数字 其他数字出现两次 3 找出数
  • 互联网摸鱼日报(2022-12-07)

    互联网摸鱼日报 2022 12 07 InfoQ 热门话题 Solo推出完全集成的云原生应用程序网络平台 经历过亿级DAU的打磨检验 抖音同款RTC到底有何魔力 性能提升 2 5 倍 字节开源高性能 C JSON 库 sonic cpp 最
  • 讲一下进程地址空间

    进程地址空间是指每个进程在计算机内存中所占用的地址空间 地址空间是指能被访问的内存地址范围 它由若干个连续的内存块组成 每个进程都有自己的地址空间 这意味着每个进程都有自己的内存地址范围 不会与其他进程冲突 进程地址空间通常被划分为几个部分
  • creator图片循环显示_CocosCreator 多块地图无限无缝滚动 组件

    地图滚动出现的原因 export enum DIRECTION LEFT 1 RIGHT 2 UP 3 DOWN 4 多块地图滚动组件 const ccclass property cc decorator ccclass export d
  • 数据结构中常见的树(BST二叉搜索树、AVL平衡二叉树、RBT红黑树、B-树、B+树、B*树)

    原文 http blog csdn net sup heaven article details 39313731 数据结构中常见的树 BST二叉搜索树 AVL平衡二叉树 RBT红黑树 B 树 B 树 B 树 转载 2014年09月16日
  • ERROR: transport error 202: gethostbyname: unknown host

    今天碰到了一个很奇怪的问题 当我启动tomcat的时候 报了如下的错误 ERROR transport error 202 gethostbyname unknown host ERROR JDWP Transport dt socket
  • 作为运维你还在想要不要学Python,听听运维老司机怎么说!

    现阶段 掌握一门开发语言已经成为高级运维工程师的必备计能 不会开发 你就不能充分理解你们系统的业务流程 你就不能帮助调试 优化开发人开发的程序 开发人员有的时候很少关注性能的问题 这些问题就得运维人员来做 一个业务上线了 导致CPU使用过高
  • Python数据可视化入门教程(非常详细)

    什么是数据可视化 数据可视化是为了使得数据更高效地反应数据情况 便于让读者更高效阅读 通过数据可视化突出数据背后的规律 以此突出数据中的重要因素 如果使用Python做数据可视化 建议学好如下这四个Python数据分析包 分别是 Panda
  • springboot整合ueditor(jsp)踩过的坑(富文本上传本地视频)(亲身经历)

    有一天老板突然找我让我改富文本 一脸懵逼 不过也不能推啊默默地接下了 大家都知道现在的富文本视频功能都是只有上传链接的没有从本地上传这一说 就连现在的csdn的也是 于是我找了好多个 最终发现百度的ueditor可以 经过几天的日夜 甚至牺
  • vue框架如何将侧边栏完全隐藏

    vue框架如何将侧边栏完全隐藏 如何将vue的左侧边栏在缩进的时候完全隐藏呢 效果图如下 找到目录src style sidebar scss 然后搜索 hideSidebar可以搜出两个 不要慌 下面的时手机端的 我们拉到上面的 hide
  • 【算法日志】哈希表应用:set和map容器,哈希表的使用(day5)

    代码随想录60day 链表 day4 链表 day3 目录 前言 一 三种哈希结构 数组 散列技术 哈希思想 哈希碰撞 set 集合 map 映射 二 哈希表的一些应用 总结 前言 哈希表 也叫散列表 是一种较为常用的数据结构 我们常用的数
  • 1486. XOR Operation in an Array

    class Solution public int xorOperation int n int start int nret start for int m 1 m lt n m nret nret start 2 m return nr
  • 编译原理(4)LR(0)语法分析程序设计(Python实现)

    1 实验要求 1 已知文法G S 0 S E 1 E aA 2 E bB 3 A cA 4 A d 5 B cB 6 B d 手工建立文法G S 的LR 0 的项目集规范族DFA和LR 0 分析表 2 根据清华大学版 编译原理 第3版 教材
  • Jfugue编程概要

    转自 http www sudu cn info html edu java 20060912 304274 html JFugue是个用于音乐作曲的Java API 和其他的音乐API不同 他能够让你用数据字符串来指定音符 乐器 和弦 及