HELP!Simple MIDI player based on Sequencer:how to set Volume?

Hi,i'm Roberto,i'm student and i'm realizing a simple midi player in java (using java1.5 and javax.sound.midi package).....the program has a gui and it can just play midi files,and the player is a class based on a Sequencer object:so the method play() initializes a Sequence object from a file and this is given as parameter to the sequencer,so it runs with Sequencer.start();......
my BIG problem is:"how can change the volume when playng if the player's class is created as above?","how can i realize a method setVolume(int volume)?"......please help me!!!!!

Did the previous post fix the problem?
At what point should the synthesizer and sequencer be opened?
Can the volume be set at anytime during playback?
I have a similar problem and i tried both of these solutions and they did not work for me.
Heres my code:
    /** The midi sequencer */
    private Sequencer sequencer = null;
    /** The synthesizer (for volume control) */
    private Synthesizer synthesizer = null;
    /** The volume (as a percentage) */
    private double gain = 100.0d;
     * Default constructor.
     * @since 1.0
    public MidiPlayer() {
        try {
             // get the system sequencer
            this.sequencer = MidiSystem.getSequencer();
            // get the system synthesizer
            this.synthesizer = MidiSystem.getSynthesizer();
            // open the sequencer
            this.sequencer.open();
            // open the synthesizer
            this.synthesizer.open();
            // link the sequencer to the synthesizer
            this.sequencer.getTransmitter().setReceiver(this.synthesizer.getReceiver());
            // set this class to list for meta events
            // (end of track event in particular)
            this.sequencer.addMetaEventListener(this);
        } catch (MidiUnavailableException ex) {
            // TODO error handling
             ex.printStackTrace();
    public void play(Sequence sequence, boolean loop) {
        if (this.sequencer != null && sequence != null && this.sequencer.isOpen()) {
            try {
                 // give the sequencer the sequence
                 this.sequencer.setSequence(sequence);
                // start the sequencer
                 this.sequencer.start();
                //set the loop flag
                this.loop = loop;
            } catch (InvalidMidiDataException e) {
                e.printStackTrace();
                // TODO error handling
     public void setGain(double gain) {
          this.gain = gain;
         // change the percent value to a respective gain value
        int value = (int) (127 * (double) (this.gain / 100.0));
         // modify the volume of the sequence
        MidiChannel[] channels = this.synthesizer.getChannels();
        for(int i = 0; i < channels.length; i++) {
             channels.controlChange(7, value);
          MidiChannel[] channels = this.synthesizer.getChannels();
          for (int i = 0; i < channels.length; i++) {
               channels[i].controlChange(7, (int) (127 * (this.gain / 100.0)));

Similar Messages

  • How to set volume with AudioServicesPlaySystemSound?

    I got playing sound with AudioServicesPlaySystemSound working, its quite simple but theres no documentation on how to set volume at all. Is it possible and how?

    Did you ever find an answer to this? I need to do the same thing.

  • How to set volume using Powershell script?

    I would like to know on how to set volume under Window 7 Home 64 bits system using Powershell script.
    Such as 8000 levels as default
    Does anyone have any suggestions?
    Thanks in advance for any suggestions
    Thanks in advance for any suggestions

    Try this.
    Function Set-SpeakerVolume{
    Param (
    [switch]$min,
    [switch]$max,
    [int]$Percent
    $wshShell = new-object -com wscript.shell
    If ($min){
    1..50 | % {$wshShell.SendKeys([char]174)}
    ElseIf ($max){
    1..50 | % {$wshShell.SendKeys([char]175)}
    elseif($Percent){
    1..50 | % {$wshShell.SendKeys([char]174)}
    1..($Percent/2) |% {$wshShell.SendKeys([char]175)}
    Else{
    $wshShell.SendKeys([char]173)
    This works in Windows 8.1.
    Stolen / Modified from
    http://blogs.technet.com/b/heyscriptingguy/archive/2013/07/28/weekend-scripter-cheesy-script-to-set-speaker-volume.aspx, which took me 20 seconds of (apparently) lucky searching.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • How to set Volume for Nokia N95(8GB)

    Hey,
    I own a Nokia N95 (8GB)
    works rather well...
    Some how i have managed to damage the Volume Buttons on the side of the phone and my volume for my music is set to the default "Volume Level"...(Which isn't very loud)
    I need some help 'how to higher the volume without using those buttons on the side'
    Please,
    thanks Brad

    Doh!
    You're right! Connect the remote (Like the AD-54) and use the remote to control the volume.
    Message Edited by el_loco on 03-Jun-2008 12:43 AM
    640K Should be enough for everybody
    El_Loco Nokia Video Blog

  • How to set volume levels in individual apps.

    I know on windows, you can set the volume for programs in the background, how do I do something similar to this on my mac?
    Best Regards,
        Patrick

    No, unfortunately.
    There is no  Volume Mixer / Windows  like utility available in OS X.
    Google it. I do not use any third party utility.
    Best.

  • Need help: Flex  record webcam problem, how to setting Brightness,Contrast,Saturation and Sharpness

    Hello, dear all
    Please help me!
    Flex  record webcam problem, how to setting Brightness,Contrast,Saturation and Sharpness?
    nsOutGoing=new NetStream(nc);
    nsOutGoing.attachCamera(m_camera);
    nsOutGoing.publish(filename, "record");
    I want to control the Brightness,Contrast,Saturation and Sharpness for the recorded flv file.
    At present, I only can control the videodisplay object, but I can not able to control Camera.
    Thanks very much!!
    kimi
    MSN: [email protected]

    Can I change a Video object to to Camera object, If yes, How do??
    nsOutGoing.attachCamera(video as Camera);// it does not work rightly
    thanks

  • How to set an Application Item from PL/SQL

    I am attempting to set an Application Item
    After login to my app, I want to retrieve a row from my SETTINGS table and populate some Application Items with the settings information so that I can
    display some of that settings information on every page.
    Just to start, I created one Application Item named F106_YEAR
    I then created a Shared Components Application Process which executes on New Session: After Authentication
    I created this process as an Anynomous PL/SQL block.
    declare
    aucyr varchar(4);
    begin
    select year into auctyr
    from settings;
    :F106_YEAR := aucyr;
    end;
    I've tried a couple of other Syntax tricks attempting to reference the Application Item F106_YEAR from within PL/SQL (like V('F106_YEAR') but nothing seems to be working.
    I'm sure that I am missing something simple. Can someone tell me how to set an Application Item from PL/SQL?
    Thanks in advance.

    I'm still doing something wrong because this is not working for me.
    I've tried both of the following versions as an Application Process set to run on New Session after Authentication:
    declare
    auction_year varchar(4);
    begin
    select year into auction_year
    from PBUUC.SETTINGS where rownum < 2;
    :F106_AUCTION_YEAR:=auction_year;
    end;
    and I also tried:
    declare
    auction_year varchar(4);
    begin
    select year into auction_year
    from PBUUC.SETTINGS where rownum < 2;
    APEX_UTIL.SET_SESSION_STATE (p_name, p_value);
    end;
    F106_YEAR is a global Item (shared components).
    The select statement works just fine in SQL*PLUS so I know that it is correct.
    If I run the debugger and log into the application, here is the output. Shouldn't I see my Application Process get called if it is set to run on New Session after Validation?
    My Application process is named RETRIEVE_AUCTION_SETTINGS
    0.01: A C C E P T: Request="P101_PASSWORD"
    0.01: Metadata: Fetch application definition and shortcuts
    0.01: alter session set nls_language="AMERICAN"
    0.01: alter session set nls_territory="AMERICA"
    0.01: ...NLS: Set Decimal separator="."
    0.01: ...NLS: Set NLS Group separator=","
    0.01: ...NLS: Set date format="DD-MON-RR"
    0.01: ...Setting session time_zone to -04:00
    0.01: NLS: wwv_flow.g_flow_language_derived_from=0: wwv_flow.g_browser_language=en-us
    0.01: Fetch session state from database
    0.02: ...Check session 695371898690095 owner
    0.02: ...Check for session expiration:
    0.02: ...Metadata: Fetch Page, Computation, Process, and Branch
    0.02: Session: Fetch session header information
    0.02: ...Metadata: Fetch page attributes for application 106, page 101
    0.03: ...Validate item page affinity.
    0.03: ...Validate hidden_protected items.
    0.03: ...Check authorization security schemes
    0.03: Session State: Save form items and p_arg_values
    0.03: ...Session State: Save "P101_USERNAME" - saving same value: "jps"
    0.03: Processing point: ON_SUBMIT_BEFORE_COMPUTATION
    0.03: Branch point: BEFORE_COMPUTATION
    0.03: Computation point: AFTER_SUBMIT
    0.03: Tabs: Perform Branching for Tab Requests
    0.03: Branch point: BEFORE_VALIDATION
    0.03: Perform validations:
    0.03: Branch point: BEFORE_PROCESSING
    0.03: Processing point: AFTER_SUBMIT
    0.03: ...Process "Set Username Cookie": PLSQL (AFTER_SUBMIT) begin owa_util.mime_header('text/html', FALSE); owa_cookie.send( name=>'LOGIN_USERNAME_COOKIE', value=>lower(:P101_USERNAME)); exception when others then null; end;
    0.04: ...Process "Login": PLSQL (AFTER_SUBMIT) wwv_flow_custom_auth_std.login( P_UNAME => :P101_USERNAME, P_PASSWORD => :P101_PASSWORD, P_SESSION_ID => v('APP_SESSION'), P_FLOW_PAGE => :APP_ID||':1' );
    0.06: ...Process "Clear Page(s) Cache": CLEAR_CACHE_FOR_PAGES (AFTER_SUBMIT) 101
    0.06: Nulling cache for application "106" page: 101
    0.00:
    0.00: S H O W: application="106" page="1" workspace="" request="" session="695371898690095"
    0.01: alter session set nls_language="AMERICAN"
    0.01: alter session set nls_territory="AMERICA"
    0.01: ...NLS: Set Decimal separator="."
    0.01: ...NLS: Set NLS Group separator=","
    0.01: ...NLS: Set date format="DD-MON-RR"
    0.01: ...Setting session time_zone to -04:00
    0.01: NLS: wwv_flow.g_flow_language_derived_from=0: wwv_flow.g_browser_language=en-us
    0.01: Application 106, Authentication: CUSTOM2, Page Template: 2904114531488186
    0.01: ...Session ID 695371898690095 can be used
    0.01: ...Application session: 695371898690095, user=JPS
    0.01: ...Determine if user "JPS" workspace "1040027630222986" can develop application "106" in workspace "1040027630222986"
    0.01: ...Check for session expiration:
    0.01: Session: Fetch session header information
    0.01: ...Metadata: Fetch page attributes for application 106, page 1
    0.01: Fetch session state from database
    0.02: Branch point: BEFORE_HEADER
    0.02: Fetch application meta data
    0.02: Computation point: BEFORE_HEADER
    0.02: Processing point: BEFORE_HEADER
    0.03: Show page template header
    0.03: Computation point: AFTER_HEADER
    0.03: Processing point: AFTER_HEADER     
    0.04: Computation point: BEFORE_BOX_BODY
    0.04: Processing point: BEFORE_BOX_BODY
    0.04: Region: Auction_Title F106_AUCTION_YEAR

  • How to set multiple operating units in before report trigger

    hi all
    can any one help me out in getting clear in how to set multiple operating units in before report trigger in oracle report.
    as we set single operating unit (mo_global.set_policy.context('S',81); as 81 is my operating unit).then who to set for multiple operating unit at run time.

    Sounds like eBusiness Suite, right? Better ask this in the appropriate forum.

  • How to implement Search Help in Interacive Form based on WebDynpro Java?

    Hi Experts,
    How to implement Search Help in Interacive Form based on WebDynpro Java?
    Could someone please provide the prerequisites and the code for the same.
    Regards,
    Shobhit

    Extend the controller and get the handle of the current row of the VO. Set set the attribute context filed accordingly. Also get the handle fo the flexbean and set the context. According rendering would change.
    Regards
    Sumit

  • How to display f4 help for a field based on value of another field

    Hello All,
    I have 4 fields : Sales Org : VBAK-VKORG, Distrib Channel : RV50A-VTWEG, Div : RV50A-SPART, Sold-to-party : KUAGV-KUNNR.
    The second field depends on the first one, the third on the second one and the fourth on the first field.
    However, when each of the second third and fourth fields' f4 help is displayed, the values are independent of the previous fields. How do I set the f4 help to display values based on the respective fields?
    Regards,
    Mithun

    Please be sure that you are searching the forums before posting. This exact same question was asked just yesterday:
    F4 help to input field
    In particular study the section and the linked help document for ddic search helps export/importing parameters and the requirements for DDic Structure/table usage for the parameter mapping.

  • How can I do a simple MIDI track (no virtual instrument)?

    I'm having the hardest time trying to figure out how to do a simple MIDI recording. So far as I can tell, I can only record MIDI data if I select a virtual instrument for the MIDI track. When I used to use Cubase, I could just record the straight MIDI signal without having to select an "output" for it, and then load up whatever instrument I wanted to use later. Can I do that with Logic 9? I record some MIDI stuff live, and I'd like to not have to bog down my machine with running live virtual instruments.
    Mainly what I'm doing is recording the MIDI data of a set of VDrums, so that when I get to mixing later on, I can trash the crappy v-drum sounds and use DFH Superior for my drums.
    Much thanks for any advice ahead of time!
    Clint
    http://www.moreofYOUinthemonitor.com
    discover your role in worship

    Cool. I'll check this out and see if it's that easy for me. i feel like I tried that, but it wouldn't show any signal until I inserted a virtual instrument. I'll try again and make sure I do it right.
    What we're doing while playing live is using the Roland Vdrum sounds live (and recording the vdrum sounds themselves, as well), and also recording the MIDI data to a MIDI track. Later during mixing, I'll mute all the vdrum audio and pipe the MIDI track through DFH Sup. I have a v-drum preset I can then apply so that the MIDI data will trigger the software correctly. In the studio, I use DFH and listen to it during recording.

  • Adobe flash player has stopped working how to rectify please help

    adobe flash player has stopped working how to rectify please help

    Can you please tell us your operating system and browser version?  In addition, please try going to this page to see if Flash Player loads and reports its version.
    http://helpx.adobe.com/flash-player/kb/find-version-flash-player.html

  • Midi Network ... How does one set it up?

    I've been trying to set up a simple midi network between my main computer and my laptop. Thus far I can't get anything to work. The instruction are NOT clear at all .. about how to set up a connection .. or at least what one needs to do for both machines. Can some kind soul please suggest what I need to do to make this work.
    Everytime I try it I get "Can't connect" .. even though sessions on both systems are recognized .. so I know the ethernet is working fine .. but I can't get this to work.
    Hope someone can help.
    Tah
    Heto

    I used the instructions found here, which worked perfectly. I networked my Powerbook G4 and my iMac and used instruments loaded into RAX on my powerbook"
    http://www.soundonsound.com/sos/mar07/articles/dpworkshop_0307.htm
    J.

  • Simple mp3 player not working :( action script error

    Hi Everyone!
    I'm wondering if anyone can help with this problem:
    I am currently designing a website and creating a simple mp3 player with an on / off function but doesn't appear to be working. I am getting this error:
    1095: Syntax error: A string literal must be terminated before the line break.
    1083: Syntax error: end of program is unexpected.
    1084: Syntax error: expecting rightparen before end of program.
    1084: Syntax error: expecting rightparen before end of program.
    1084: Syntax error: expecting rightparen before end of program.
    1084: Syntax error: expecting rightparen before end of program.
    I have uploaded a zip file containing the images and FLA file. I'm wondering if someone wouldn't mind taking a look for me and telling me how to fix this problem:
    http://www.c-recordz.co.uk/download/mp3_player.zip
    Thanks
    Davies

    Hi Davies,
    On line 19 don't break the line, Flash will do it for you... other aspect that I would recomend is to not put the '$' on the variables. In AS2 variables don't need to be declared as such (although it's a good policy), instead of the '$' put the 'var' word, as you already have in those variables.
    Greetings
    Leo

  • New comer ask 2 simple questions:how to set the use of the right click of

    New comer ask 2 simple questions:how to set the use of the right click of your mouse?
    I don't know why when i click the right button of my mouse in logic, sometimes it's the same funcion as my left one, some times it's the same function that opens the tool menu....But in MacOSX,it's all okay.Just the weired thing in logic ,please help
    2.is there any kind of filter in Score? I mean, in midi track I have a C1 note, and I don't want the C1 note shown in my score, I want every note show which are above C2, like a filter. I think this is helpful dealling with some keyswich things,how can we do that?

    In Preferences -> Global -> Editing you can choose weather right click is assignable or opens the tools box.
    Not to sure about the score dude

Maybe you are looking for

  • RWRUN60: Problem with parameter value containing space between single quote

    Hi All I'm using RWRUN60 to generate my report by following way: C:\orant\BIN\RWRUN60.EXE userid=DBUser/dbpasswor@db BACKGROUND="NO" BATCH="YES" DESFORMAT="pdf" DESNAME="C:\report.pdf" DESTYPE="FILE" ORIENTATION="LANDSCAPE" PARAMFORM="NO" P_REPORTID=

  • HT201320 Can't get to my mailbox

    I got a new Iphone 4s.  I set up my mail account and have an icon on the main screen showing that there are new messages.  But when I tap the mail icon, it keeps taking me to the Wecome to Mail screen, as though I need to set up a new account.  How c

  • Function Module to get planned Quantity from posting date

    hi, i need one function module which takes plant and posting date date as an input parameter and get the Planned quantity for that range of that ...i dont want to fetch it from material since the report is run for the whole plant(werks).so it has got

  • How to "lock" a cell reference in Numbers??

    HELP! I am a recent convert from Windows based machines to Apple. I am very familiar with Excel and need to figure out how to do something in Numbers.... I need to know how to lock a cell reference so that when you drag the formula down or across it

  • Error opening URL-local files-mac

    I'm using a var and an Array code on an empty move clip. The code is set on an "Actions" layer. The code checks good. All files are on my desktop. When I test movie I get 'Error opening URL 'file:///Andrea/Users/user/Desktop/BosigerWk6/swfs/one.swf'