Exemplo n.º 1
0
  public MainFrame() {
    super("Cacophony");
    setFocusTraversalKeysEnabled(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setExtendedState(JFrame.MAXIMIZED_BOTH);

    final Synthesizer syn = system.getSynthesizer();
    instruments = new DefaultMidiInstruments(syn);

    grates.register(GrateModes.KEYS, new DefaultKeyGrate());
    grates.register(GrateModes.COMMAND, new DefaultCommandGrate(instruments, status));

    final JPanel mainView = new JPanel();
    add(mainView, BorderLayout.CENTER);

    add(status.view(), BorderLayout.SOUTH);

    final SwitchableView[] switchableViews = ocelot.views();
    mainView.setLayout(new GridLayout(switchableViews.length + 1, 1));

    final List<Toridor> views =
        meerkat.views(
            reader.read(
                new StringReader(
                    "Vibraphone\n"
                        + "50,51,52_16|54_32|53_16|56_16|55_16|58_16|55_16|56_16|58_16|53_16|68_16|70_16|68_16|70_16|68_16|70_16|67_16\n"
                        + "String Ensemble 1\n"
                        + "70_64|70_16|61,62_16|64_32|53_16|56_16|55_16|58_16|55_16|56_16|58_16|53_16|68_16|70_16|68_16|70_16|68_16|70_16|67_16\n"
                        + "Flute\n"
                        + "70_64|61,62_16|64_32|53_16|56_16|55_64\n"
                        +
                        //                "Lead 8 (bass + lead)\n" +
                        //                "70_64|61,62_16\n" +
                        "Seashore\n"
                        + "70_64|61,62_16|64_32|53_16|56_16|55_16|58_16|70_16|68_16|70_16|67_16\n"
                        + "Gunshot\n"
                        + "70_64|61,62_16|64_32|53_16|56_16|55_16|58_16|55_16|56_16|58_16|53_16|68_16|70_16|68_16|70_16|68_16|70_16|67_16")),
            instruments);

    for (final SwitchableView switchableView : switchableViews) {
      mainView.add(switchableView.view());
    }

    for (int i = 0; i < views.size(); i++) {
      final Toridor toridor = views.get(i);
      if (i < switchableViews.length) switchableViews[i].show(toridor);
    }

    ocelot.setCandidates(views);

    manager = new DefaultToridorManager(views);

    mainView.add(infoPanel.view());

    infoPanel.refresh();
    addKeyListener(
        new KeyAdapter() {
          public void keyPressed(final KeyEvent e) {
            final Operation operation = grates.handle(e);
            status.clearMessage();
            operation.fold(
                new ChannelOp() {
                  public boolean op(final H<Ocelot, Control, Boolean> h) {
                    return h.h(ocelot, control);
                  }
                },
                new ControlOp() {
                  public boolean op(final G<Control, Boolean> g) {
                    g.g(control);
                    updateInfo();
                    return true;
                  }
                },
                new SystemOp() {
                  public boolean op(final H<SoundSystem, ToridorManager, Boolean> h) {
                    return h.h(system, manager);
                  }
                },
                new UiOp() {
                  public boolean op(final G<Grates, Boolean> g) {
                    g.g(grates);
                    updateInfo();
                    return true;
                  }
                },
                new NoOp() {
                  public boolean op() {
                    // FIX 17/03/12 This may be a bit verbose as it picks up when a meta key is
                    // pressed.
                    return true;
                  }
                });
          }
        });
  }
Exemplo n.º 2
0
 private void updateInfo() {
   final GrateModes mode = grates.getMode().getOr(GrateModes.NONE);
   infoPanel.display(mode.name(), control.getOctave(), control.getDurationText());
 }