|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
Audio alarms |
Guest
|
Post subject: Audio alarms |
Post rating: 0
|
Posted: Mon 22 Jun, 2009, 20:38
|
|
User rating: -
|
Can we program sound alarms on level prices or indicators. Thank you for your answer.
|
|
|
|
 |
RoadRunner
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Tue 23 Jun, 2009, 09:54
|
|
User rating: 3
Joined: Wed 18 May, 2011, 16:25 Posts: 331 Location: SwitzerlandSwitzerland
|
Try this one: import java.io.*; import javax.sound.sampled.*;
... playSound("C:/temp/testsound.wav", 10); ...
private void playSound(String _sWavFile, int _nRepeats) { try { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(_sWavFile)); AudioFormat af = audioInputStream.getFormat(); int nSize = (int) (af.getFrameSize() * audioInputStream.getFrameLength()); byte[] audio = new byte[nSize]; DataLine.Info info = new DataLine.Info(Clip.class, af, nSize); audioInputStream.read(audio, 0, nSize);
for(int i=0; i < _nRepeats; i++) { Clip clip = (Clip)AudioSystem.getLine(info); clip.open(af, audio, 0, nSize); clip.start(); } } catch(Exception e) { console.getOut().println(e.getMessage()); } }
Best, RR.
|
|
|
|
 |
Guest
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Thu 25 Jun, 2009, 17:23
|
|
User rating: -
|
It works very well, thank you RoadRunner.
|
|
|
|
 |
API Support
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Fri 26 Jun, 2009, 08:38
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
If you keep sound files in "My Strategies/files" you can avoid to use full access annotation and get rid of warning message appearing on every start.
|
|
|
|
 |
Guest
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Tue 06 Oct, 2009, 16:03
|
|
User rating: -
|
Hello, Sorry for my poor English and programming skills............... I'm interested in the audio alarm indicator, so it would be kind of you if anyone could explain step by step the process of compilling the right way java files ? I try to compil it but get syntax error : this is below the report message. Thanks for all Happy and fun trading Angel 14:57:58 ---------- 14:57:58 Syntax error, insert "EnumBody" to complete EnumDeclaration 14:57:58 ^ 14:57:58 console.getOut().println(e.getMessage()); 14:57:58 20. ERROR in C:\Users\Al\AppData\Local\Temp\jfxide\tmp\Audio alarm.java (at line 30)
|
|
|
|
 |
[MarkieMark]
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Wed 07 Oct, 2009, 06:49
|
|
User rating: 0
Joined: Fri 02 Oct, 2009, 14:36 Posts: 3
|
the few suggestions at the top there are pseudocode, you need to include the call to playSound() in a method; you should really learn the java language reasonably, to write a strategy - even a minimal one see https://java.sun.com/docs/books/tutorial/index.html Mark
|
|
|
|
 |
[nuvolare]
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Sat 05 Mar, 2011, 15:18
|
|
User rating: 0
Joined: Sat 05 Mar, 2011, 15:06 Posts: 4
|
Hello to everyone, I'm opening again this post because I'm new of Jforex and I wish have some allarm when my order start, or it take the S.L. or T.P. How I can do to do this? I tried to read and use the code that you propose, but I don't know were I've to put in my windows, and same on my Mac. Could I please know were I've to put those code? Thank you for you answer
|
|
|
|
 |
RoadRunner
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Tue 08 Mar, 2011, 15:05
|
|
User rating: 3
Joined: Wed 18 May, 2011, 16:25 Posts: 331 Location: SwitzerlandSwitzerland
|
Hi Nuvolare, you just have to paste the code into your strategy code and then call playSound(<filepath to wav>, <repeat times>); in your code where you want the audio to play (e.g. after submitting your order). Other than adding import java.io.*; import javax.sound.sampled.*;
no other external references are needed. If your wav-files are located outside your strategy file path, then you have to add @RequiresFullAccess in your strategy class definition to allow your strategy to access the file path where you locate your wav-files. Example for a strategy file Test.java with full access to your pc's file structure: @RequiresFullAccess public class Test implements IStrategy { ... }
I hope this helps. Best, RR.
|
|
|
|
 |
[nuvolare]
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Fri 11 Mar, 2011, 20:34
|
|
User rating: 0
Joined: Sat 05 Mar, 2011, 15:06 Posts: 4
|
RoadRunner wrote: Hi Nuvolare,
you just have to paste the code into your strategy code and then call playSound(<filepath to wav>, <repeat times>); in your code where you want the audio to play (e.g. after submitting your order). Other than adding import java.io.*; import javax.sound.sampled.*;
no other external references are needed.
If your wav-files are located outside your strategy file path, then you have to add @RequiresFullAccess in your strategy class definition to allow your strategy to access the file path where you locate your wav-files.
Example for a strategy file Test.java with full access to your pc's file structure: @RequiresFullAccess public class Test implements IStrategy { ... }
I hope this helps. Best, RR. Ok, so I pasted the code in the strategy, and in the left down corner there are a small windows and there in "Strategy" there are the code calls MySoundNotification. Now when I submit an order what I've to do? Sorry but I don't know much about the code. Thank you
|
|
|
|
 |
RoadRunner
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Mon 14 Mar, 2011, 15:59
|
|
User rating: 3
Joined: Wed 18 May, 2011, 16:25 Posts: 331 Location: SwitzerlandSwitzerland
|
Could you please post your code?
|
|
|
|
 |
[nuvolare]
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Sat 19 Mar, 2011, 19:06
|
|
User rating: 0
Joined: Sat 05 Mar, 2011, 15:06 Posts: 4
|
RoadRunner wrote: Could you please post your code? Ok, this is the code package jforex;
import com.dukascopy.api.*; import java.io.*; import javax.sound.sampled.*;
/** * @author martins.ceske * * Simple strategy which demonstrates how to play sound on each successfully * submitted order. * */ public class MySoundNotificationStrategy implements IStrategy { private IEngine engine; private IOrder myOrder; private IConsole console; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); }
public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { if(message.getType()== IMessage.Type.ORDER_SUBMIT_OK){ //on each successfully submitted order playing sound playSound("C:/tmp/TestSnd.wav", 10); } }
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } //this method take care of playing your file from given location private void playSound(String _sWavFile, int _nRepeats) { try { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(_sWavFile)); AudioFormat af = audioInputStream.getFormat(); int nSize = (int) (af.getFrameSize() * audioInputStream.getFrameLength()); byte[] audio = new byte[nSize]; DataLine.Info info = new DataLine.Info(Clip.class, af, nSize); audioInputStream.read(audio, 0, nSize);
for(int i=0; i < _nRepeats; i++) { Clip clip = (Clip)AudioSystem.getLine(info); clip.open(af, audio, 0, nSize); clip.start(); } } catch(Exception e) { console.getOut().println(e.getMessage()); } } }
|
|
|
|
 |
RoadRunner
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Thu 07 Apr, 2011, 09:36
|
|
User rating: 3
Joined: Wed 18 May, 2011, 16:25 Posts: 331 Location: SwitzerlandSwitzerland
|
Hi nuvolare, sorry, I missed out your post... If you haven't already solved the problem, first thing you have to do is to include the @RequiresFullAccess annotation in your class definition. Without that annotation java will have no access to files outside the strategy path such as your wav file. change public class MySoundNotificationStrategy implements IStrategy { ... to @RequiresFullAccesspublic class MySoundNotificationStrategy implements IStrategy { ... I didn't try your code, but at first sight everything else looks good. Best, RR.
|
|
|
|
 |
[nuvolare]
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Fri 08 Apr, 2011, 05:51
|
|
User rating: 0
Joined: Sat 05 Mar, 2011, 15:06 Posts: 4
|
RoadRunner wrote: Hi nuvolare, sorry, I missed out your post... If you haven't already solved the problem, first thing you have to do is to include the @RequiresFullAccess annotation in your class definition. Without that annotation java will have no access to files outside the strategy path such as your wav file. change public class MySoundNotificationStrategy implements IStrategy { ... to @RequiresFullAccesspublic class MySoundNotificationStrategy implements IStrategy { ... I didn't try your code, but at first sight everything else looks good. Best, RR. Ok, thank you for your reply, and this is the reply from the computer 2011-04-08 04:50:42 ---------- 2011-04-08 04:50:42 RequiresFullAccesspublic cannot be resolved to a type 2011-04-08 04:50:42 ^^^^^^^^^^^^^^^^^^^^^^^^ 2011-04-08 04:50:42 @RequiresFullAccesspublic class MySoundNotificationStrategy implements IStrategy { 2011-04-08 04:50:42 1. ERROR in /var/folders/d9/d9I6K4OiEoe5yyHhShUHSE+++TI/-Tmp-/jfxide/tmp/MySoundNotificationStrategy.java (at line 13) 2011-04-08 04:50:42 ---------- 2011-04-08 04:50:40 Compiling MySoundNotificationStrategy.java 2011-04-08 04:50:37 ---------- 2011-04-08 04:50:37 RequiresFullAccesspublic cannot be resolved to a type 2011-04-08 04:50:37 ^^^^^^^^^^^^^^^^^^^^^^^^ 2011-04-08 04:50:37 @RequiresFullAccesspublic class MySoundNotificationStrategy implements IStrategy { 2011-04-08 04:50:37 1. ERROR in /var/folders/d9/d9I6K4OiEoe5yyHhShUHSE+++TI/-Tmp-/jfxide/tmp/MySoundNotificationStrategy.java (at line 13) 2011-04-08 04:50:37 ---------- 2011-04-08 04:50:23 Compiling MySoundNotificationStrategy.java
|
|
|
|
 |
RoadRunner
|
Post subject: Re: Audio alarms |
Post rating: 0
|
Posted: Sat 09 Apr, 2011, 08:23
|
|
User rating: 3
Joined: Wed 18 May, 2011, 16:25 Posts: 331 Location: SwitzerlandSwitzerland
|
Sorry nuvolare, there was a misspelling in the code snippet in my previous posting. There of course should be a blank between the annotation and 'public': RequiresFullAccess public class MySoundNotificationStrategy implements IStrategy { ... Best, RR.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|