Class

# DesktopNotePlayer

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

## Description

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

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                       | Type                                                       | Read-Only | Shared |
|--------------------------------------------|------------------------------------------------------------|-----------|--------|
| `Handle<desktopnoteplayer.handle>`         | `Ptr</api/data_types/additional_types/ptr>`                | ✓         |        |
| `Index<desktopnoteplayer.index>`           | `Integer</api/data_types/integer>`                         |           |        |
| `Instrument<desktopnoteplayer.instrument>` | `Integer</api/data_types/integer>`                         |           |        |
| `Name<desktopnoteplayer.name>`             | `String</api/data_types/string>`                           | ✓         |        |
| `Scope<desktopnoteplayer.scope>`           | `Integer</api/data_types/integer>`                         | ✓         |        |
| `Window<desktopnoteplayer.window>`         | `DesktopWindow</api/user_interface/desktop/desktopwindow>` | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                   | Parameters                                                                                  | Returns | Shared |
|----------------------------------------|---------------------------------------------------------------------------------------------|---------|--------|
| `Close<desktopnoteplayer.close>`       |                                                                                             |         |        |
| `PlayNote<desktopnoteplayer.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 |
|--------------------------------------|------------|---------|
| `Closing<desktopnoteplayer.closing>` |            |         |
| `Opening<desktopnoteplayer.opening>` |            |         |

## Property descriptions

<div id="desktopnoteplayer.handle">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

> Returns a handle to the control.
>
> This property is read-only.
>
> For interfacing with Mac APIs using `Declares</api/language/declare>`, **DesktopControl.Handle** returns NSViews (except for `DesktopToolbar</api/user_interface/desktop/desktoptoolbar>`).
>
> On Windows returns the HWND of the control.
>
> On Linux it returns a GtkWidget.
>
> The following gets a handle to the control.
>
> ``` xojo
> Var p As Ptr = Me.Handle
> ```

<div id="desktopnoteplayer.index">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.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.

<div id="desktopnoteplayer.instrument">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.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">DesktopNotePlayer</span>).
>
> This example specifies the Church Organ as the instrument.
>
> ``` xojo
> NotePlayer1.Instrument = 20
> NotePlayer1.PlayNote(60, 60)
> ```

<div id="desktopnoteplayer.name">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.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="desktopnoteplayer.scope">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.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.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> This is a designtime-only property and thus can only be set in the Inspector and is not accessible via code.
>
> </div>
>
> If the Scope of a control is set to Private, it cannot be accessed from outside its parent window.

<div id="desktopnoteplayer.window">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.Window

**Window** As `DesktopWindow</api/user_interface/desktop/desktopwindow>`

> The control's parent window.
>
> This property is read-only.
>
> This code gets the parent window's Title property.
>
> ``` xojo
> MessageBox(Me.Window.Title)
> ```

## Method descriptions

<div id="desktopnoteplayer.close">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.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="desktopnoteplayer.playnote">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.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="desktopnoteplayer.closing">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.Closing

**Closing**

> The control is closing.

<div id="desktopnoteplayer.opening">

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

</div>

<div class="rst-class">

forsearch

</div>

DesktopNotePlayer.Opening

**Opening**

> The control is about to be displayed. Use this event to initialize a control.
>
> The Opening event is called after the Constructor.
>
> Be warned that initializing control property values using the Constructor instead of the Opening event may result in those property values being overwritten by what is set in the Inspector. For best results, use the Opening 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 Opening()
>   Me.AcceptPictureDrop
>   Me.AcceptFileDrop("JPEG")
> End Sub
> ```

## 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 |

## 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">DesktopNotePlayer</span> is not supported on Linux.

## 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
  Thread.SleepCurrent(500)
Next
```

## Compatibility

|                       |                |
|-----------------------|----------------|
| **Project Types**     | Desktop        |
| **Operating Systems** | macOS, Windows |

<div class="seealso">

`DesktopControl</api/user_interface/desktop/desktopcontrol>` parent class.

</div>
