10 January, 2008

Simple Java MIDI synthesizer sample

Another multi-media sample - simplest Java MIDI synthesizer.


MidiSynthesizerSample.java

import javax.sound.midi.*;
 
public class MidiSynthesizerSample {
  public static void main(String[] args) {
      int[] notes = new int[]{60, 62, 64, 65, 67, 69, 71, 72, 72, 71, 69, 67, 65, 64, 62, 60};
      try {
          Synthesizer synthesizer = MidiSystem.getSynthesizer();
          synthesizer.open();
          MidiChannel channel = synthesizer.getChannels()[0];
 
          for (int note : notes) {
              channel.noteOn(note, 50);
              try {
                  Thread.sleep(200);
              } catch (InterruptedException e) {
                  break;
              } finally {
                  channel.noteOff(note);
              }
          }
      } catch (MidiUnavailableException e) {
          e.printStackTrace();
      }
  }
}


See example of Java MIDI application:
XenoHarmonica

09 January, 2008

Simple Java MIDI player sample

New Year!

XenoHarmonica
- is a musical project. It is a bayan keyboard emulator, Java MIDI application for personal computers.
Now everybody can play bayan (button accordion).

XenoHarmonica is free for education and non-commercial usage.

Program based on Java MIDI API.
In this article I provide an example of simplest MIDI player.

Maybe somebody else going to create MIDI program :-)



MidiPlayerSample.java
package xantorohara.xenoharmonica.samples;
 
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import java.io.FileInputStream;
 
public class MidiPlayerSample {
 
    public static void main(String[] args) {
        try {
            Sequencer sequencer = MidiSystem.getSequencer();
            if (sequencer == null)
                throw new MidiUnavailableException();
            sequencer.open();
            FileInputStream is = new FileInputStream("sample.mid");
            Sequence mySeq = MidiSystem.getSequence(is);
            sequencer.setSequence(mySeq);
            sequencer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 

Windows XP hibernate mode problem

Do you have a problem with Hibernate mode in Windows XP?
And you can't turn on Hibernate mode from Power Options Panel, it says: "The process cannot access the file because it is being used by another process".
I found one crasy method how to resolve this problem on my computer (AMD64/1G RAM/MB Asus M2NE/Video Asus N7600/IDE HDD).

  • Delete file: WINDOWS\system32\drivers\atapi.sys (it will be restored by Windows).

  • Manualy enable hibernate mode (now it isn't throw error message).

  • Switch computer to Hibernate mode.


Is it helpful?

22 November, 2007

HowTo batch replace string in the set of files

This script replaces all occurrences of 'oldString' with 'newString' in all files in the current directory and all subdirectories.



xqx_replace.sh

#!/bin/bash

if test -z "$1" -o -z "$2"; then
echo Replace all occurrences of 'oldString' with 'newString' in all files in the current directory and all subdirectories.
echo Usage: $0 oldSting newString
exit
fi

OLDSTRING=$1
NEWSTRING=$2

replace() {
echo "$1"
mv "$1" "$1".bak
sed s/$OLDSTRING/$NEWSTRING/g "$1".bak >"$1"
}

check() {
while read; do
if test -n "`grep -l $OLDSTRING \"$REPLY\"`"; then
replace "$REPLY"
fi
done
}

find . -type f |check

01 November, 2007

Oracle XE installation problem

Have a problem with Oracle Database 10g Express Edition?
Oracle is installed but doesn't work?

This is caused by that your account is given from domain server or your system has non-English locale.

HowTo resolve this problem:

  1. Create local user (this user should not be a domain account).


  2. Set OS system locale to English (US or UK, via Regional and Language Options), reboot.


  3. Install Oracle XE under local user (via runas console program or via Run as... from Windows Explorer popup menu).


  4. Open file "Oracle\app\oracle\product\10.2.0\server\NETWORK\ADMIN\sqlnet.ora
    and comment (via # symbol) or remove line SQLNET.AUTHENTICATION_SERVICES = (NTS)


  5. Open shell, type sqlplus oracle_user/oracle_password and work with Oracle XE.