Class
NotePlayer
Warning
This item was deprecated in version 2021r3. Please use DesktopNotePlayer as a replacement.
Description
Plays musical notes via the QuickTime on Macintosh and the MIDI functions on Windows.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
Property descriptions
NotePlayer.Handle
Handle As Integer
Returns a handle to the control.
This property is read-only.
For interfacing with Mac APIs using Declare).
On Windows returns the HWND of the control.
On Linux it returns a GtkWidget.
The following gets a handle to the control.
Var i As Integer = Me.Handle
NotePlayer.Index
Index As Integer
If the control is used in a control set, this specifies the control's index in the set.
This property is read-only.
The control set is often used to manage a group of RadioButtons since a single RadioButton in a window doesn't make much sense. Most typically, you create an instance of the RadioButton, assign 0 to its Index property, and then duplicate it. This increments the value of Index for each new instance but retain the original control's name.
To determine which RadioButton the user clicked, use the Action event handler of the control set. The parameter Index contains the value of Index for the RadioButton that was clicked. The event handler is this:
Sub Action(Index As Integer)
Label1.Text = "You chose radio button " + index.ToString + "."
End Sub
To set a RadioButton in a control set, you use its Index property to refer to the RadioButton whose value you want to set. For example, the following line selects the second RadioButton from code:
RadioButton1(1).Value = True ' 0-based
NotePlayer.Instrument
Instrument As Integer
The number of the musical instrument to be used to play the note (see the chart in the Instruments section of the NotePlayer.
This example specifies the Church Organ as the instrument.
NotePlayer1.Instrument = 20
NotePlayer1.PlayNote(60, 60)
NotePlayer.Left
Left As Integer
The left side of the control in local coordinates (relative to the window).
This property is read-only.
NotePlayer.MouseX
MouseX As Integer
The X coordinate of the mouse (points). Measured from the top-left corner of the control.
This property is read-only.
This code is in the MouseDown event of a TextField and displays the X-coordinate at the point of the MouseDown event.
Me.Value = Str(Me.MouseX)
NotePlayer.MouseY
MouseY As Integer
The Y coordinate of the mouse (points). Measured from the top-left corner of the control.
This property is read-only.
This code is in the MouseDown event of a TextField and displays the Y-coordinate at the point of the MouseDown event.
Me.Value = Str(Me.MouseY)
NotePlayer.Name
Name As String
The name of the control. Set the name of the control in the Inspector.
This property is read-only.
NotePlayer.PanelIndex
PanelIndex As Integer
If the control has been placed on a TabPanel or PagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a TabPanel or PagePanel control, it returns the panel number. If the control is not on a PagePanel or TabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use PagePanel.SelectedPanelIndex.
This code displays the panel index of the control that is on the page.
Label3.Value = Str(Me.PanelIndex)
NotePlayer.Scope
Scope As Integer
Used to determine whether access to the control is Public (0) or Private (2). The default is Public.
This property is read-only.
If the Scope of a control is set to Private, it cannot be accessed from outside its parent window.
NotePlayer.Top
Top As Integer
The top of the control in local coordinates (relative to the window).
This property is read-only.
NotePlayer.Window
Window As Window
The control's parent window.
This property is read-only.
This code gets the parent window's Title property.
TextField1.Text = Me.Window.Title
Method descriptions
NotePlayer.Close
Close
Closes a control.
Closing a control permanently removes the control from memory, making it impossible to access. You can close both non-indexed controls and indexed controls. When you close an indexed control, the indexes for the remaining controls will shift downward so that the indexes start with zero and are consecutive.
The following code closes the control. When this is executed from a visible control, the control disappears from the window.
Me.Close
NotePlayer.PlayNote
PlayNote(Pitch As Integer, Velocity As Integer)
Plays the note specified by the pitch at the velocity specified.
The following example plays the Church Organ at the passed Pitch and Velocity.
NotePlayer1.Instrument = 20
NotePlayer1.PlayNote(60, 60)
The following line of code stops the note:
NotePlayer1.PlayNote(60, 0)
Event descriptions
NotePlayer.Close
Close
The control is about to close.
NotePlayer.Open
Open
The control is about to be displayed. Use this event to initialize a control.
The Open event is called after the Constructor.
Be warned that initializing control property values using the Constructor instead of the Open event may result in those property values being overwritten by what is set in the Inspector. For best results, use the Open event for control initialization rather than the control Constructor.
If the control is supposed to handle drag and drop, you need to tell it which type of item it needs to be able to handle. The following example informs the control that pictures and files can be dropped on it. The type of the file it needs to support is specified via the File Types Editor.
Sub Open()
Me.AcceptPictureDrop
Me.AcceptFileDrop("JPEG")
End Sub
Notes
When calling the PlayNote method, the pitch is represented as a number from 0 to 127 where middle C is 60. Incrementing by 1 raises the pitch by a half step. Decreasing by 1 decreases the pitch by a half step. You can also express the value of pitch as a number from 256 to 32767, i.e. pitch*256. Use this to specify half-steps. For example, if you want a pitch of 60.5, specify 60.5*256=15488 as the value of Pitch.
The velocity parameter is a scale from 0 to 127 that represents how hard the key is pressed. 127 represents a very hard key press. 0 represents the key no longer being pressed. When calling the PlayNote method, the note played will continue to play until it is played again with a velocity of 0.
Linux
The NotePlayer is not supported on Linux.
Instruments
Instrument |
Value |
Instrument |
Value |
---|---|---|---|
Acoustic Grand Piano |
1 |
Soprano Sax |
65 |
Bright Acoustic Piano |
2 |
Alto Sax |
66 |
Electric Grand Piano |
3 |
Tenor Sax |
67 |
Honky-tonk Piano |
4 |
Baritone Sax |
68 |
Rhodes Piano |
5 |
Oboe |
69 |
Chorused Piano |
6 |
English Horn |
70 |
Harpsichord |
7 |
Bassoon |
71 |
Clavinet |
8 |
Clarinet |
72 |
Celesta |
9 |
Piccolo |
73 |
Glockenspiel |
10 |
Flute |
74 |
Music Box |
11 |
Recorder |
75 |
Vibraphone |
12 |
Pan Flute |
76 |
Marimba |
13 |
Bottle blow |
77 |
Xylophone |
14 |
Shakuhachi |
78 |
Tubular bells |
15 |
Whistle |
79 |
Dulcimer |
16 |
Ocarina |
80 |
Draw Organ |
17 |
Square Lead |
81 |
Percussive Organ |
18 |
Saw Lead |
82 |
Rock Organ |
19 |
Calliope |
83 |
Church Organ |
20 |
Chiffer |
84 |
Reed Organ |
21 |
Synth Lead 5 |
85 |
Accordion |
22 |
Synth Lead 6 |
86 |
Harmonica |
23 |
Synth Lead 7 |
87 |
Tango Accordion |
24 |
Synth Lead 8 |
88 |
Acoustic Nylon Guitar |
25 |
Synth Pad 1 |
89 |
Acoustic Steel Guitar |
26 |
Synth Pad 2 |
90 |
Electric Jazz Guitar |
27 |
Synth Pad 3 |
91 |
Electric clean Guitar |
28 |
Synth Pad 4 |
92 |
Electric Guitar muted |
29 |
Synth Pad 5 |
93 |
Overdriven Guitar |
30 |
Synth Pad 6 |
94 |
Distortion Guitar |
31 |
Synth Pad 7 |
95 |
Guitar Harmonics |
32 |
Synth Pad 8 |
96 |
Wood Bass |
33 |
Ice Rain |
97 |
Electric Bass Fingered |
34 |
Soundtracks |
98 |
Electric Bass Picked |
35 |
Crystal |
99 |
Fretless Bass |
36 |
Atmosphere |
100 |
Slap Bass 1 |
37 |
Bright |
101 |
Slap Bass 2 |
38 |
Goblin |
102 |
Synth Bass 1 |
39 |
Echoes |
103 |
Synth Bass 2 |
40 |
Space |
104 |
Violin |
41 |
Sitar |
105 |
Viola |
42 |
Banjo |
106 |
Cello |
43 |
Shamisen |
107 |
Contrabass |
44 |
Koto |
108 |
Tremolo Strings |
45 |
Kalimba |
109 |
Pizzicato Strings |
46 |
Bagpipe |
110 |
Orchestral Harp |
47 |
Fiddle |
111 |
Timpani |
48 |
Shanai |
112 |
Acoustic String Ensemble 1 |
49 |
Tinkle bell |
113 |
Acoustic String Ensemble 2 |
50 |
Agogo |
114 |
Synth Strings 1 |
51 |
Steel Drums |
115 |
Synth Strings 2 |
52 |
Woodblock |
116 |
Aah Choir |
53 |
Taiko Drum |
117 |
Ooh Choir |
54 |
Melodic Tom |
118 |
Synvox |
55 |
Synth Tom |
119 |
Orchestra Hit |
56 |
Reverse Cymbal |
120 |
Trumpet |
57 |
Guitar Fret Noise |
121 |
Trombone |
58 |
Breath Noise |
122 |
Tuba |
59 |
Seashore |
123 |
Muted Trumpet |
60 |
Bird Tweet |
124 |
French Horn |
61 |
Telephone Ring |
125 |
Brass Section |
62 |
Helicopter |
126 |
Synth Brass 1 |
63 |
Applause |
127 |
Synth Brass 2 |
64 |
Gunshot Table |
128 |
Drum Kit |
16385 |
Sample code
The following plays "do-re-mi-fa-so-la-ti-do":
NotePlayer1.Instrument = 1
' Notes for Do Re Mi Fa So La Ti Do
' see http://en.wikipedia.org/wiki/Do-Re-Mi from The Sound of Music http://en.wikipedia.org/wiki/The_Sound_of_Music
' (C, D, E, F, G, A, B, C)
Var doReMi(7) As Integer
doReMi = Array(60, 62, 64, 65, 67, 69, 71, 60)
For Each note As Integer In doReMi
NotePlayer1.PlayNote(note, 100)
' Pause to let note play
App.SleepCurrentThread(500)
Next
Compatibility
All project types on all supported operating systems.