<div class="meta" robots="noindex">

</div>

Class

# NotePlayer

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2021r3. Please use `DesktopNotePlayer</api/user_interface/desktop/desktopnoteplayer>` as a replacement.

</div>

## Description

Plays musical notes via the QuickTime on Macintosh and the MIDI functions on Windows.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                | Type                               | Read-Only | Shared |
|-------------------------------------|------------------------------------|-----------|--------|
| `Handle<noteplayer.handle>`         | `Integer</api/data_types/integer>` | ✓         |        |
| `Index<noteplayer.index>`           | `Integer</api/data_types/integer>` | ✓         |        |
| `Instrument<noteplayer.instrument>` | `Integer</api/data_types/integer>` |           |        |
| `Left<noteplayer.left>`             | `Integer</api/data_types/integer>` | ✓         |        |
| `MouseX<noteplayer.mousex>`         | `Integer</api/data_types/integer>` | ✓         |        |
| `MouseY<noteplayer.mousey>`         | `Integer</api/data_types/integer>` | ✓         |        |
| `Name<noteplayer.name>`             | `String</api/data_types/string>`   | ✓         |        |
| `PanelIndex<noteplayer.panelindex>` | `Integer</api/data_types/integer>` |           |        |
| `Scope<noteplayer.scope>`           | `Integer</api/data_types/integer>` | ✓         |        |
| `Top<noteplayer.top>`               | `Integer</api/data_types/integer>` | ✓         |        |
| `Window<noteplayer.window>`         | `Window</api/deprecated/window>`   | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters                                                                                  | Returns | Shared |
|----------------------------------|---------------------------------------------------------------------------------------------|---------|--------|
| `Close<noteplayer.close_method>` |                                                                                             |         |        |
| `PlayNote<noteplayer.playnote>`  | Pitch As `Integer</api/data_types/integer>`, Velocity As `Integer</api/data_types/integer>` |         |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                            | Parameters | Returns |
|---------------------------------|------------|---------|
| `Close<noteplayer.close_event>` |            |         |
| `Open<noteplayer.open>`         |            |         |

## Property descriptions

<div id="noteplayer.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Handle

**Handle** As `Integer</api/data_types/integer>`

Returns a handle to the control.

This property is read-only.

For interfacing with Mac APIs using `` Declare</api/language/declare>`s, RectControl.Handle returns NSViews (except for :doc:`Toolbar</api/deprecated/toolbar> ``).

On Windows returns the HWND of the control.

On Linux it returns a GtkWidget.

The following gets a handle to the control.

``` xojo
Var i As Integer = Me.Handle
```

<div id="noteplayer.index">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Index

**Index** As `Integer</api/data_types/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:

``` xojo
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:

``` xojo
RadioButton1(1).Value = True ' 0-based
```

<div id="noteplayer.instrument">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Instrument

**Instrument** As `Integer</api/data_types/integer>`

The number of the musical instrument to be used to play the note (see the chart in the Instruments section of the <span class="title-ref">NotePlayer</span>.

This example specifies the Church Organ as the instrument.

``` xojo
NotePlayer1.Instrument = 20
NotePlayer1.PlayNote(60, 60)
```

<div id="noteplayer.left">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Left

**Left** As `Integer</api/data_types/integer>`

The left side of the control in local coordinates (relative to the window).

This property is read-only.

<div id="noteplayer.mousex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.MouseX

**MouseX** As `Integer</api/data_types/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</api/deprecated/textfield>` and displays the X-coordinate at the point of the MouseDown event.

``` xojo
Me.Value = Str(Me.MouseX)
```

<div id="noteplayer.mousey">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.MouseY

**MouseY** As `Integer</api/data_types/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</api/deprecated/textfield>` and displays the Y-coordinate at the point of the MouseDown event.

``` xojo
Me.Value = Str(Me.MouseY)
```

<div id="noteplayer.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Name

**Name** As `String</api/data_types/string>`

The name of the control. Set the name of the control in the Inspector.

This property is read-only.

<div id="noteplayer.panelindex">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.PanelIndex

**PanelIndex** As `Integer</api/data_types/integer>`

If the control has been placed on a `TabPanel</api/deprecated/tabpanel>` or `PagePanel</api/deprecated/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</api/deprecated/tabpanel>` or `PagePanel</api/deprecated/pagepanel>` control, it returns the panel number. If the control is not on a `PagePanel</api/deprecated/pagepanel>` or `TabPanel</api/deprecated/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<pagepanel.selectedpanelindex>`.

This code displays the panel index of the control that is on the page.

``` xojo
Label3.Value = Str(Me.PanelIndex)
```

<div id="noteplayer.scope">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Scope

**Scope** As `Integer</api/data_types/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.

<div id="noteplayer.top">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Top

**Top** As `Integer</api/data_types/integer>`

The top of the control in local coordinates (relative to the window).

This property is read-only.

<div id="noteplayer.window">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Window

**Window** As `Window</api/deprecated/window>`

The control's parent window.

This property is read-only.

This code gets the parent window's Title property.

``` xojo
TextField1.Text = Me.Window.Title
```

## Method descriptions

<div id="noteplayer.close_method">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

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.

``` xojo
Me.Close
```

<div id="noteplayer.playnote">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.PlayNote

**PlayNote**(Pitch As `Integer</api/data_types/integer>`, Velocity As `Integer</api/data_types/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*.

``` xojo
NotePlayer1.Instrument = 20
NotePlayer1.PlayNote(60, 60)
```

The following line of code stops the note:

``` xojo
NotePlayer1.PlayNote(60, 0)
```

## Event descriptions

<div id="noteplayer.close_event">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NotePlayer.Close

**Close**

The control is about to close.

<div id="noteplayer.open">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

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.

``` xojo
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 <span class="title-ref">NotePlayer</span> 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":

``` xojo
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.

## See also

`Control</api/deprecated/control>` parent class; `Control</api/deprecated/control>` class.
