官术网_书友最值得收藏!

Automating the counter

As we noticed, in the last example, you need to click on the bang button to advance the counter. Can we do it automatically? The following example will provide you with the answer. It is another important concept in Pure Data. When you work on animation in later chapters, it requires the same technique.

Save As your last example with the name autoCounter.pd. We will now modify it with the auto-counting function. The new object we are going to use is metro. It is the metronome for counting the beat when you practice musical instruments. We add a metro object with a numeric parameter of 1000. This number is the duration of each beat, with units in millisecond. 1000 milliseconds will be one second. The second new object is a toggle box. You can choose it from Put | Toggle. It is another type of button, such as an on/off switch. We connect the toggle box to the inlet of the metro object and a bang box to the outlet of the metro object.

In Run Mode, click on the toggle box. You will notice a cross indicating the ON state. Note that the bang box flashes automatically once in every second. To stop, click on the toggle box again. The cross disappears.

The toggle box starts and stops the metro box. A cross in the toggle box sends out a value 1. An empty toggle box sends out a value 0. The number next to the metro box is the duration in milliseconds for every count. The number 1000 means one thousand milliseconds, that is one second. For every second, the metro box sends out a bang message through its outlet. To complete the patch, we can connect the bang message from the metro box to the bang input for the float object.

We can also use a number box for the right inlet of the metro object to control the counting frequency, instead of the fixed rate of 1000 milliseconds. The smaller the value, the faster the metro counts.

When there are more boxes in the patch window, the connection links grow messier. Pd provides a wireless connection for you to tidy up the links. They are the send and receive boxes. The following example makes use of send and receive boxes to eliminate the intersecting connection. The name cnt next to send and receive is a variable name you could use to describe the connection. You can use whatever appropriate name as long as it is unique and identical in both the send and receive boxes. You can imagine it is an invisible link connecting the send and receive boxes with the same variable name.

主站蜘蛛池模板: 简阳市| 贺州市| 承德市| 河池市| 新邵县| 岑溪市| 常德市| 麻城市| 邵东县| 林口县| 伊宁县| 东乌| 施甸县| 济南市| 延川县| 连城县| 新和县| 登封市| 安龙县| 临邑县| 湟源县| 阿巴嘎旗| 深泽县| 阳西县| 淮北市| 西昌市| 彩票| 磐安县| 阳原县| 平谷区| 怀宁县| 建湖县| 南昌县| 江都市| 静乐县| 桐庐县| 任丘市| 呼图壁县| 赤壁市| 汶上县| 桦川县|