use consistent base access in the define macros.
[AROS.git] / workbench / c / Play.c
blob9a241b93063a01d6e71c247ce25abc34d6c55349
1 /*
2 Copyright © 2012-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 Play
15 SYNOPSIS
17 FILE/A
19 LOCATION
23 FUNCTION
25 Play a sound file, using datatypes.library
27 INPUTS
29 FILE f -- Filename to play
31 RESULT
33 Sound should play to the default audio device
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
43 INTERNALS
45 HISTORY
47 ******************************************************************************/
49 #define DEBUG 0
50 #include <aros/debug.h>
52 #include <exec/memory.h>
53 #include <proto/exec.h>
54 #include <proto/dos.h>
55 #include <proto/alib.h>
56 #include <proto/datatypes.h>
58 #include <datatypes/datatypesclass.h>
59 #include <datatypes/soundclass.h>
61 #include <aros/shcommands.h>
63 static inline BOOL isPlayable(struct Library *DataTypesBase, Object *obj)
65 struct DTMethod *dtm;
67 for (dtm = GetDTTriggerMethods(obj); dtm && dtm->dtm_Label; dtm++) {
68 if (dtm->dtm_Method == STM_PLAY)
69 return TRUE;
72 return FALSE;
75 AROS_SH1H(Play, 44.1, "Play a sound file using DataTypes\n",
76 AROS_SHAH(STRPTR, , FILE, /A, NULL, "File to play\n"))
78 AROS_SHCOMMAND_INIT
80 LONG result = RETURN_FAIL;
81 struct Library *DataTypesBase;
82 STRPTR file = SHArg(FILE);
84 if ((DataTypesBase = OpenLibrary("datatypes.library", 0))) {
85 Object *o;
86 if ((o = NewDTObject(file, SDTA_SignalTask, FindTask(NULL),
87 SDTA_SignalBitNumber, SIGB_SINGLE, TAG_END))) {
88 if (isPlayable(DataTypesBase, o)) {
89 struct dtTrigger msg;
90 msg.MethodID = DTM_TRIGGER;
91 msg.dtt_GInfo = NULL;
92 msg.dtt_Function = STM_PLAY;
93 msg.dtt_Data = NULL;
94 if (0 == DoDTMethodA(o, NULL, NULL, (Msg)&msg)) {
95 Wait(SIGF_SINGLE | SIGBREAKF_CTRL_C);
96 result = RETURN_OK;
97 } else {
98 Printf("Can't play \"%s\"\n", file);
99 result = RETURN_FAIL;
101 } else {
102 Printf("\"%s\" is not a DataType playable sound file\n", file);
103 result = RETURN_FAIL;
105 DisposeDTObject(o);
106 } else {
107 Printf("Can't open %s as a DataType object\n", file);
109 CloseLibrary(DataTypesBase);
110 } else {
111 Printf("Can't open datatypes.library\n");
114 return result;
116 AROS_SHCOMMAND_EXIT