Ciao a tutti, sono nuovo, ho appena letto i regolamenti pertanto spero di non violare alcuna regola del forum. Espongo il mio problema:
ho le seguenti due classi e dovrei effettuare il passaggio della stringa tempo e timbro ad un'altra classe in modo da poterla modificare li.ho creato il metodo getTempo() ma non so come chiamarlo correttamente nell'altra classe.
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;
import java.util.*;
public class LetturaFile {
public LetturaFile() throws Exception {
FileInputStream in = new FileInputStream("/Users/giuseppecaponetto/Desktop/prova.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
File file =new File("/Users/giuseppecaponetto/Desktop/prova.txt");
FileReader fr = new FileReader(file);
LineNumberReader lnr = new LineNumberReader(fr);
int linenumber = 0;
while (lnr.readLine() != null){
linenumber++;
}
System.out.println("Total number of lines : " + linenumber);
lnr.close();
String strLine;
String[] mioarray;
mioarray = new String[linenumber];
String note = "";
String stringreplacer = "";
for (int j = 0; j < linenumber; j++){
mioarray[j] = br.readLine();
}
for (int i = 0; i < linenumber; i++){
System.out.println(mioarray[i]);
}
for (int z = 3; z <linenumber; z++){
note = note + mioarray[z];
}
String subnotes = note.substring(5);
String notepulite = subnotes.replaceAll(" \\\\", stringreplacer);
System.out.println(notepulite);//note con la virgola come separatore
String[] arraynote = notepulite.split(",");
System.out.println(arraynote[7]);//l'indice dell array parte da zero!
String tempo = mioarray[1].substring(6);
String timbro = mioarray[2].substring(7);
}
public String getTempo(){
return tempo;
}
}
ecco la classe in cui dovrei chiamarlo:
import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.midi.Synthesizer;
import java.io.*;
public class OpenInstrument {
Synthesizer synth;
MidiChannel channels[];
Soundbank bank;
Instrument instrs[];
Instrument myInstrument;
Patch myPatch;
OpenInstrument() {
try
{
// Locate the default synthesizer
synth = MidiSystem.getSynthesizer();
// Open the synthesizer
synth.open();
// Get the available Midi channels - there are usually 16
channels = synth.getChannels();
// Get the synth's soundbank where all the sounds are stored
bank = synth.getDefaultSoundbank();
// Load all the available instruments
synth.loadAllInstruments(bank);
// Get a list of the available instruments
instrs = synth.getLoadedInstruments();
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
public void PrintInstrumentList() {
for (int i = 0; i < instrs.length; i++) {
System.out.println(i + ") " + instrs[i].getName());
}
}
public void SetInstrument(int instrumentNum, int channelNum) {
myInstrument = instrs[instrumentNum];
// Get the information describing the instrument - the
// patch contains the soundbank and program number
myPatch = myInstrument.getPatch();
// Set a channel to use the guitar instrument
channels[1].programChange(myPatch.getBank(),myPatch.getProgram());
}
public void PlayChord() {
try {
// Play a chord on channel 1
int basekey = 60;//do medio
int tempo = 100;//in millisecondi
channels[1].noteOn(60, 127); //c
Thread.sleep(tempo);
channels[1].noteOn(47, 127); //B
Thread.sleep(tempo);
channels[1].noteOn(52, 127); //E
Thread.sleep(tempo);
channels[1].noteOn(55, 127); //G
Thread.sleep(tempo);
channels[1].noteOn(59, 127); //B
Thread.sleep(tempo);
channels[1].noteOn(64, 127); //E
// Give the notes some time to play
Thread.sleep(tempo);
// Turn the notes off
channels[1].allNotesOff();
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
public void close() {
// Close the synthesizer device
synth.close();
}
}