Projecte Proj4

De Wikijoan
Dreceres ràpides: navegació, cerca

El Proj4 és un aclaratori de com utilitzo el hardware disponible (CASIO CTK-731, Yamaha WX5, Alesis DM5) com a mòdul de so o com a controlador MIDI, i com utilitzo el software disponible (fluidsynt, Virtual Keyboard,...). Hi ha quatre combinacions:

Aquí es publica estrictament el codi. En aquest Aclaratori_MidiShare:_tocar_i_fer_sonar_música._Solucions_software_i_hardware#Programant_MidiShare_amb_Java link es publica l'explicació de totes les combinacions hardware i software, i les connexions que s'han de fer.

Contingut

v1: tocar software i sonar software

Parteixo de MidiShareIOTest.java.

Necessito MidiAppl.class. He de compilar.

$ cd /usr/src/midishare/lang/java/native/grame/midishare
$ sudo javac -classpath /usr/src/midishare/lang/java/native -d /usr/src/midishare/lang/java/native/grame/midishare MidiAppl.java

D'aquesta manera compilem MidiAppl.java i obtenim les classes en el mateix directori: MidiAppl.class, DriverInfos.class, MidiApplImpl.class, Midi.class, MidiPollingThread.class, ReadEvInfo.class, SmpteLoc.class, WriteEvInfo.class, MidiApplPolling.class, MidiException.class, MidiTask.class, SlotInfos.class, SyncInfo.class

Tota la nomenclatura dels ports és per a Windows, o sigui que l'elimino.$ cd /usr/src/midishare/lang/java/native/grame/midishare $ sudo javac -classpath /usr/src/midishare/lang/java/native -d /usr/src/midishare/lang/java/native/grame/midishare MidiAppl.java

D'aquesta manera compilem MidiAppl.java i obtenim les classes en el mateix directori: MidiAppl.class, DriverInfos.class, MidiApplImpl.class, Midi.class, MidiPollingThread.class, ReadEvInfo.class, SmpteLoc.class, WriteEvInfo.class, MidiApplPolling.class, MidiException.class, MidiTask.class, SlotInfos.class, SyncInfo.class

Tota la nomenclatura dels ports és per a Windows.

script proj4_v1_UA25EX.sh

#!/bin/bash
/usr/src/midishare/src/linux/applications/msconnect/msconnect &
/usr/src/midishare/src/linux/applications/msdisplay/msdisplay &
/usr/src/midishare/src/linux/applications/mscontrol/mscontrol &
/usr/bin/vkeybd &
sleep 2
xterm -e 'bash -c "/usr/local/bin/fluidsynth -a alsa -m midishare -o audio.alsa.device='plughw:1' -c 2 -z 64 -r 96000 -l  /home/joan/soundfonts/collections/Casio_VL_1.SF2"' &
sleep 2
xterm -e '/usr/local/bin/msAlsaSeq "ALSA_MS_bridge" -i "Virtual Keyboard":0' &
sleep 2
# java -classpath /usr/src/midishare/lang/java/native:/home/joan/workspace/Proj4/bin v1.Proj4

Proj4.class

package v1;

import java.awt.*;
import java.awt.event.*;

import grame.midishare.*;


public class Proj4 extends MidiAppl {

    private int field;
	
	public Proj4() {

    }

    public void Open(String name) throws MidiException {
        super.Open(name);
        configureFilter();
    }

    /* kill active sensing */
    void configureFilter() {
        int i;
        for (i = 0; i < 256; i++) {
            Midi.AcceptType(filter, i, 1);
        }

        for (i = 0; i < 16; i++) {
            Midi.AcceptChan(filter, i, 1);
        }
        
        Midi.AcceptType(filter, Midi.typeActiveSens, 0);
    }

    /** Simply notify that an input event occurred, print what kind */
    public void ReceiveAlarm(int ev) {
    	int event_newnote;
    	int event_newprogram;
    	switch (Midi.GetType(ev)) {
            case Midi.typeNote :
                System.out.println("Proj4, received typeNote");
                //afegim una nota d'octava
                event_newnote = Midi.NewEv(Midi.typeNote); 
	            if (event_newnote != 0) {
	                Midi.SetChan(event_newnote, Midi.GetChan(ev)); // set the Midi channel
	                Midi.SetField(event_newnote, 0, Midi.GetData0(ev)+12); //nota
	                Midi.SetField(event_newnote, 1, Midi.GetData1(ev));  //volum 
	            }
	            if (Midi.GetData0(ev)!=60){
		            Midi.SendIm(this.refnum, ev);
		            Midi.SendIm(this.refnum, event_newnote);
	            }

	            break;
            case (Midi.typeKeyOn):
                System.out.println("Proj4, received typeKeyOn: " + Midi.GetData0(ev));

	        	//canvi de programa
            	if (Midi.GetData0(ev)>=60 & Midi.GetData0(ev)<=72 ){
	        		event_newprogram = Midi.NewEv(Midi.typeProgChange); 
	        		if (event_newprogram != 0) {
	            		Midi.SetChan(event_newprogram, Midi.GetChan(ev));
	            		Midi.SetData0(event_newprogram, Midi.GetData0(ev)-60); //canvi de programa
	            		Midi.SendIm(this.refnum, event_newprogram);
	            		System.out.println("Proj4, canvi de programa: " +  (Midi.GetData0(ev)-60));
	        		}
	        	}
            	
            	//afegim una nota d'octava
            	event_newnote = Midi.NewEv(Midi.typeKeyOn); 
	            if (event_newnote != 0) {
	                Midi.SetChan(event_newnote, Midi.GetChan(ev)); // set the Midi channel
	                Midi.SetField(event_newnote, 0, Midi.GetData0(ev)+12); //nota
	                Midi.SetField(event_newnote, 1, Midi.GetData1(ev));  //volum                  
	            }
	            if (Midi.GetData0(ev)!=60){
		            Midi.SendIm(this.refnum, ev);
		            //Midi.SendIm(this.refnum, event_newnote);
	            }

	            break;
            case Midi.typeKeyOff :
                System.out.println("Proj4, received typeKeyOff: " + Midi.GetData0(ev));
            	
            	//apaguem la nota d'octava
            	event_newnote = Midi.NewEv(Midi.typeKeyOff); 
	            if (event_newnote != 0) {
	                Midi.SetChan(event_newnote, Midi.GetChan(ev)); // set the Midi channel
	                Midi.SetField(event_newnote, 0, Midi.GetData0(ev)+12); //nota
	                Midi.SetField(event_newnote, 1, 0);  //volum                  
	            }
	            if (Midi.GetData0(ev)!=60){
		            Midi.SendIm(this.refnum, ev);
		            //Midi.SendIm(this.refnum, event_newnote);
	            }

	            break;

        }
        
    }

 
    public static void main(String args[]) {

        int installed = 0;
        try {
            installed = Midi.Share();
        }
        catch (UnsatisfiedLinkError e) {
            e.printStackTrace();
            System.out.println(
                "\nMidiShare Java API probably not installed properly, grame.midishare.Midi.Share() barfed.\n" + e);
            System.exit(0);
        }

        final Proj4 midiHandler = new Proj4();

        try {
            midiHandler.Open("Proj4");
            Midi.Connect(midiHandler.refnum, 0, 1);
            Midi.Connect(0, midiHandler.refnum, 1);
            // Check output connection
            int connected = Midi.IsConnected(midiHandler.refnum, 0);
            System.out.println("Connected for input? " + connected);

            // Check input connection
            connected = Midi.IsConnected(0, midiHandler.refnum);
            System.out.println("Connected for output? " + connected);

            //em connecto a fluidsynth
            int ref_fluidsynth;
            if ((ref_fluidsynth = Midi.GetNamedAppl("fluidsynth")) > 0) Midi.Connect (midiHandler.refnum,ref_fluidsynth, 1);
            //em connecto al mscontrol
            int ref_mscontrol;
            if ((ref_mscontrol = Midi.GetNamedAppl("mscontrol")) > 0) Midi.Connect (ref_mscontrol,midiHandler.refnum, 1);
            // msAlsaSeq "bridge". Amb aconnectgui connecto el vkeybd amb el bridge (driver midishare-ALSA)
            //i ara he de connectar el bridge amb la meva aplicació (que està connectada al fluidsynth)
            int ref_bridge;
            if ((ref_bridge = Midi.GetNamedAppl("ALSA_MS_bridge")) > 0) Midi.Connect (ref_bridge,midiHandler.refnum, 1);
            //com a control, connecto Proj4 al msdisplay
            int ref_display;
            if ((ref_display = Midi.GetNamedAppl("msdisplay")) > 0) Midi.Connect (midiHandler.refnum,ref_display, 1);
            
        }
        catch (MidiException e1) {
            System.out.println("Error opening Proj4: " + e1);
            e1.printStackTrace();
        }

    }
}

Aquí es mostra la discussió a la llista LAU (maig-juny 2009) per arrencar Beatrix (un sintetitzador que imita els orgues Hammond) des d'un script (estudiar):

Re: [LAU] beatrix + eeepc + nanokontrol
Sunday, May 31, 2009 11:27 PM
From:
"oz" <oz@bluemonk.de>
Add sender to Contacts
To:
linux-audio-user@lists.linuxaudio.org

Very helpful, thanks a lot, Robin!
I bundled all I need to start beatrix in a little script, that I start from
an icon on my KDE-desktop now:
-----------------------------------------------------------------
#/bin/sh
# beatrix.sh virtually connects my midi-devices with beatrix and starts it.

PRESETS=/home/me/beatrix-presets.txt
BEA_DIR=/home/me/beatrix

vkeybd --preset $PRESETS &
sleep 1

BEA=$(aconnect -o -l | awk '/Virtual Raw MIDI 1-3/{print $2."0"}')

KBD=$(aseqdump -l | awk '/UM-1SX/{print $1}')
NANOK=$(aseqdump -l | awk '/nanoKONTROL/{print $1}')
VKBD=$(aseqdump -l | awk '/Virtual Keyboard/{print $1}')

aconnect $KBD $BEA
aconnect $NANOK $BEA
aconnect $VKBD $BEA

cd $BEA_DIR
$BEA_DIR/beatrix
-------------------------------------------------------------------

There were two pitfalls I had to avoid. The ID of the Virtual Raw MIDI
interface depends on the connected usb-midi-devices at boottime. Only when
nothing is connected, it has the ID 1-3 as used in the script (else 3-3 for
example). So I boot the eeepc with with my keyboard and nanokontrol unplugged.
When KDE is up, I plug them in. One klick on my script-icon and I'm ready to
play!

The second pitfall were the KDE system-sounds. They can result in '/dev/dsp
busy' when beatrix starts. Now I disabled all system-sounds in
KDE-control-center.

I like your "Jackification" and will try it after I'm familiar with the
current release of beatrix. Hopefully the author of beatrix proofs your
concept. Beatrix is hot!

- oz

On Sun, 31 May 2009 20:47:30 +0200
Robin Gareus <robin@gareus.org> wrote:

> off-list: http://rg42.org/wiki/beatrix - Bend beatix' license on your
> own account and patch it with JACK and ALSA-midi support ;)
[...]
> What is your problem with `aconnect` ? Are you looking for sth like:
>
> #/bin/sh
> BEA=$(aconnect -o -l | awk '/Virtual Raw MIDI 1-3/{print $2."0"}')
> VKBD=$(aseqdump -l | awk '/Virtual Keyboard/{print $1}')
> aconnect $BEA $VKBD

v2: tocar software i sonar hardware

Depenent de la versió en què estic, canvia el script i les connexions que s'estableixen dins el codi Java.

script proj4_v2_UA25EX.sh

#!/bin/bash
/usr/src/midishare/src/linux/applications/msconnect/msconnect &
/usr/src/midishare/src/linux/applications/msdisplay/msdisplay &
/usr/src/midishare/src/linux/applications/mscontrol/mscontrol &
/usr/bin/vkeybd &
sleep 2
xterm -e '/usr/local/bin/msAlsaSeq "ALSA_MS_bridge" -i "Virtual Keyboard":0 -o "UA-25EX":0' &
sleep 2
# java -classpath /usr/src/midishare/lang/java/native:/home/joan/workspace/Proj4/bin v1.Proj4

Proj4.class

        try {
            midiHandler.Open("Proj4");
            Midi.Connect(midiHandler.refnum, 0, 1);
            Midi.Connect(0, midiHandler.refnum, 1);
            // Check output connection
            int connected = Midi.IsConnected(midiHandler.refnum, 0);
            System.out.println("Connected for input? " + connected);

            // Check input connection
            connected = Midi.IsConnected(0, midiHandler.refnum);
            System.out.println("Connected for output? " + connected);

            //em connecto al mscontrol
            int ref_mscontrol;
            if ((ref_mscontrol = Midi.GetNamedAppl("mscontrol")) > 0) Midi.Connect (ref_mscontrol,midiHandler.refnum, 1);
            // msAlsaSeq "bridge". Amb aconnectgui connecto el vkeybd amb el bridge (driver midishare-ALSA)
            //també connecto el bridge amb la Edirol UA-25EX
            //i ara he de connectar el bridge amb la meva aplicació, en els dos sentits
            int ref_bridge;
            if ((ref_bridge = Midi.GetNamedAppl("ALSA_MS_bridge")) > 0) Midi.Connect (midiHandler.refnum,ref_bridge, 1);
            if ((ref_bridge = Midi.GetNamedAppl("ALSA_MS_bridge")) > 0) Midi.Connect (ref_bridge,midiHandler.refnum, 1);
            //com a control, connecto Proj4 al msdisplay
            int ref_display;
            if ((ref_display = Midi.GetNamedAppl("msdisplay")) > 0) Midi.Connect (midiHandler.refnum,ref_display, 1);
            
        }

v3: tocar hardware i sonar software

script proj4_v3_UA25EX.sh

#!/bin/bash
/usr/src/midishare/src/linux/applications/msconnect/msconnect &
/usr/src/midishare/src/linux/applications/msdisplay/msdisplay &
/usr/src/midishare/src/linux/applications/mscontrol/mscontrol &
sleep 2
xterm -e 'bash -c "/usr/local/bin/fluidsynth -a alsa -m midishare -o audio.alsa.device='hw:0' -c 2 -z 128 -r 44100 -l  /home/joan/soundfonts/collections/Casio_VL_1.SF2"' &
sleep 2
xterm -e '/usr/local/bin/msAlsaSeq "ALSA_MS_bridge" -i "Virtual Keyboard":0' &
sleep 2
java -classpath /usr/src/midishare/lang/java/native:/home/joan/workspace/Proj4/bin v1.Proj4

Proj4.class

...
        try {
            midiHandler.Open("Proj4");
            Midi.Connect(midiHandler.refnum, 0, 1);
            Midi.Connect(0, midiHandler.refnum, 1);
            // Check output connection
            int connected = Midi.IsConnected(midiHandler.refnum, 0);
            System.out.println("Connected for input? " + connected);

            // Check input connection
            connected = Midi.IsConnected(0, midiHandler.refnum);
            System.out.println("Connected for output? " + connected);

            //em connecto a fluidsynth
            int ref_fluidsynth;
            if ((ref_fluidsynth = Midi.GetNamedAppl("fluidsynth")) > 0) Midi.Connect (midiHandler.refnum,ref_fluidsynth, 1);
            // msAlsaSeq "bridge". Amb aconnectgui connecto el vkeybd amb el bridge (driver midishare-ALSA)
            //i ara he de connectar el bridge amb la meva aplicació (que està connectada al fluidsynth)
            int ref_bridge;
            if ((ref_bridge = Midi.GetNamedAppl("ALSA_MS_bridge")) > 0) Midi.Connect (ref_bridge,midiHandler.refnum, 1);
            //com a control, connecto Proj4 al msdisplay
            int ref_display;
            if ((ref_display = Midi.GetNamedAppl("msdisplay")) > 0) Midi.Connect (midiHandler.refnum,ref_display, 1);
            
        }
...

v4: tocar hardware i sonar hardware

script proj4_v4_UA25EX.sh

#!/bin/bash
/usr/src/midishare/src/linux/applications/msconnect/msconnect &
/usr/src/midishare/src/linux/applications/msdisplay/msdisplay &
/usr/src/midishare/src/linux/applications/mscontrol/mscontrol &
sleep 2
xterm -e '/usr/local/bin/msAlsaSeq "ALSA_MS_bridge" -i "UA-25EX":0 -o "UA-25EX":0' &
sleep 2
java -classpath /usr/src/midishare/lang/java/native:/home/joan/workspace/Proj4/bin v4.Proj4

Proj4.class

...
        try {
            midiHandler.Open("Proj4");
            Midi.Connect(midiHandler.refnum, 0, 1);
            Midi.Connect(0, midiHandler.refnum, 1);
            // Check output connection
            int connected = Midi.IsConnected(midiHandler.refnum, 0);
            System.out.println("Connected for input? " + connected);

            // Check input connection
            connected = Midi.IsConnected(0, midiHandler.refnum);
            System.out.println("Connected for output? " + connected);

            //em connecto al mscontrol
            int ref_mscontrol;
            if ((ref_mscontrol = Midi.GetNamedAppl("mscontrol")) > 0) Midi.Connect (ref_mscontrol,midiHandler.refnum, 1);
            // msAlsaSeq "bridge". Amb aconnectgui connecto el vkeybd amb el bridge (driver midishare-ALSA)
            //també connecto el bridge amb la Edirol UA-25EX
            //i ara he de connectar el bridge amb la meva aplicació, en els dos sentits
            int ref_bridge;
            if ((ref_bridge = Midi.GetNamedAppl("ALSA_MS_bridge")) > 0) Midi.Connect (midiHandler.refnum,ref_bridge, 1);
            if ((ref_bridge = Midi.GetNamedAppl("ALSA_MS_bridge")) > 0) Midi.Connect (ref_bridge,midiHandler.refnum, 1);
            //com a control, connecto Proj4 al msdisplay
            int ref_display;
            if ((ref_display = Midi.GetNamedAppl("msdisplay")) > 0) Midi.Connect (midiHandler.refnum,ref_display, 1);
            
        }
...
Eines de l'usuari
Espais de noms
Variants
Accions
Navegació
Institut Jaume Balmes
Màquines recreatives
CNC
Informàtica musical
joanillo.org Planet
Eines