Class

DesktopNotePlayer


Description

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

Properties

Name

Type

Read-Only

Shared

Handle

Ptr

Index

Integer

Instrument

Integer

Name

String

Scope

Integer

Window

DesktopWindow

Methods

Name

Parameters

Returns

Shared

Close

PlayNote

Pitch As Integer, Velocity As Integer

Events

Name

Parameters

Returns

Closing

Opening

Property descriptions


DesktopNotePlayer.Handle

Handle As Ptr

Returns a handle to the control.

This property is read-only.

For interfacing with Mac APIs using Declares, DesktopControl.Handle returns NSViews (except for DesktopToolbar).

On Windows returns the HWND of the control.

On Linux it returns a GtkWidget.

The following gets a handle to the control.

Var p As Ptr = Me.Handle

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


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

This example specifies the Church Organ as the instrument.

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

DesktopNotePlayer.Name

Name As String

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

This property is read-only.


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

Note

This is a designtime-only property and thus can only be set in the Inspector and is not accessible via code.

If the Scope of a control is set to Private, it cannot be accessed from outside its parent window.


DesktopNotePlayer.Window

Window As DesktopWindow

The control's parent window.

This property is read-only.

This code gets the parent window's Title property.

MessageBox(Me.Window.Title)

Method descriptions


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.

Me.Close

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


DesktopNotePlayer.Closing

Closing

The control is closing.


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.

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 DesktopNotePlayer is not supported on Linux.

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

Compatibility

Desktop projects on macOS and Windows operating systems.

See also

DesktopControl parent class; DesktopControl class.