import javax.swing.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class Main {
  public static void main(String[] args) {

    Scanner sc = null;
    try {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = chooser.getSelectedFile();
        sc = new Scanner(selectedFile);
      } else {
        throw new FileNotFoundException();
      }
    } catch (FileNotFoundException e) {
      System.out.println("File not found: " + args[1]);
      System.exit(0);
    }

    SoundDevice device = new SoundDevice();
    Song song = new Song(20);

    final double SLOWDOWN = (double)240/148;

    while (sc.hasNextInt()) {
      int pitch = sc.nextInt();
      double duration = SLOWDOWN * sc.nextDouble();
      song.add(MusicUtils.harmonic(pitch, duration));
    }

    song.play(device);
    //song.save(device.getFormat(), new File("twotones.wav"));
  }

}