void ResourceItem::stateChange( bool active )
{
  if ( mActive == active ) {
    return;
  }

  if ( mBlockStateChange ) {
    return;
  }

  if ( mIsSubresource ) {
    mResource->setSubresourceActive( mResourceIdentifier, active );
  } else {
    if ( active ) {
      if ( mResource->load() ) {
        mResource->setActive( true );
        if ( !mSubItemsCreated ) {
          createSubresourceItems();
        }
      }
    } else {
      // mView->requestClose must be called before mResource->save() because
      // save causes closeResource do be called.
      mView->requestClose( mResource );
      if ( mResource->save() ) {
        mResource->setActive( false );
      }
    }

    setExpanded( mResource->isActive() && childCount() > 0 );
  }

  setGuiState();
  mView->emitResourcesChanged();
}
void SingleCellSimulationViewInformationSimulationWidget::initialize(const QString &pFileName,
                                                                     CellMLSupport::CellmlFileRuntime *pRuntime,
                                                                     SingleCellSimulationViewSimulationData *pSimulationData)
{
    // Make sure that we have a CellML file runtime

    if (!pRuntime)
        return;

    // Retrieve and initialise our GUI state

    setGuiState(mGuiStates.contains(pFileName)?
                    mGuiStates.value(pFileName):
                    mDefaultGuiState);

    // Iniialise the unit of our different properties

    QString unit = pRuntime->variableOfIntegration()->unit();

    setStringPropertyItem(mStartingPointProperty->unit(), unit);
    setStringPropertyItem(mEndingPointProperty->unit(), unit);
    setStringPropertyItem(mPointIntervalProperty->unit(), unit);

    // Initialise our simulation's starting point so that we can then properly
    // reset our simulation the first time round

    pSimulationData->setStartingPoint(Core::PropertyEditorWidget::doublePropertyItem(mStartingPointProperty->value()), false);
}
void SingleCellSimulationViewInformationSolversWidget::initialize(const QString &pFileName,
                                                                  CellMLSupport::CellmlFileRuntime *pRuntime,
                                                                  SingleCellSimulationViewSimulationData *pSimulationData)
{
    // Make sure that we have a CellML file runtime

    if (!pRuntime)
        return;

    // Retrieve and initialise our GUI state

    setGuiState(mGuiStates.contains(pFileName)?
                    mGuiStates.value(pFileName):
                    mDefaultGuiState);

    // Make sure that the CellML file runtime is valid

    if (pRuntime->isValid()) {
        // Show/hide the ODE/DAE solver information

        if (mOdeSolverData)
            setPropertyVisible(mOdeSolverData->solversProperty(), pRuntime->needOdeSolver());

        if (mDaeSolverData)
            setPropertyVisible(mDaeSolverData->solversProperty(), pRuntime->needDaeSolver());

        // Show/hide the NLA solver information

        if (mNlaSolverData)
            setPropertyVisible(mNlaSolverData->solversProperty(), pRuntime->needNlaSolver());

        // Retranslate ourselves so that the property names get properly set

        retranslateUi();
    }

    // Set the unit of our different properties, if needed

    QString voiUnit = pRuntime->variableOfIntegration()->unit();

    setPropertiesUnit(mOdeSolverData, voiUnit);
    setPropertiesUnit(mDaeSolverData, voiUnit);
    setPropertiesUnit(mNlaSolverData, voiUnit);

    // Initialise our simulation's NLA solver's properties, so that we can then
    // properly reset our simulation the first time round

    if (mNlaSolverData) {
        pSimulationData->setNlaSolverName(mNlaSolverData->solversListProperty()->value()->text(), false);

        foreach (Core::Property *property, mNlaSolverData->solversProperties().value(pSimulationData->nlaSolverName()))
            pSimulationData->addNlaSolverProperty(property->name()->text(),
                                                  (property->value()->type() == Core::PropertyItem::Integer)?
                                                      Core::PropertyEditorWidget::integerPropertyItem(property->value()):
                                                      Core::PropertyEditorWidget::doublePropertyItem(property->value()),
                                                  false);
    }
}
HelmStandaloneEditor::HelmStandaloneEditor() {
  setSynth(&synth_);
  setGuiState(&gui_state_);
  keyboard_state_ = new MidiKeyboardState();
  midi_manager_ = new MidiManager(&synth_, keyboard_state_, &gui_state_, &critical_section_, this);
  computer_keyboard_ = new HelmComputerKeyboard(&synth_, keyboard_state_, &critical_section_);
  output_memory_ = new mopo::Memory(MAX_OUTPUT_MEMORY);
  memory_offset_ = 0;

  Startup::doStartupChecks(midi_manager_, computer_keyboard_);
  setAudioChannels(0, mopo::NUM_CHANNELS);

  AudioDeviceManager::AudioDeviceSetup setup;
  deviceManager.getAudioDeviceSetup(setup);
  setup.sampleRate = mopo::DEFAULT_SAMPLE_RATE;
  deviceManager.initialise(0, mopo::NUM_CHANNELS, nullptr, true, "", &setup);

  if (deviceManager.getCurrentAudioDevice() == nullptr) {
    const OwnedArray<AudioIODeviceType>& device_types = deviceManager.getAvailableDeviceTypes();

    for (AudioIODeviceType* device_type : device_types) {
      deviceManager.setCurrentAudioDeviceType(device_type->getTypeName(), true);
      if (deviceManager.getCurrentAudioDevice())
        break;
    }
  }

  const StringArray all_midi_ins(MidiInput::getDevices());

  for (int i = 0; i < all_midi_ins.size(); ++i)
    deviceManager.setMidiInputEnabled(all_midi_ins[i], true);

  deviceManager.addMidiInputCallback("", midi_manager_);

  setLookAndFeel(DefaultLookAndFeel::instance());

  gui_ = new FullInterface(synth_.getControls(),
                           synth_.getModulationSources(),
                           synth_.getMonoModulations(),
                           synth_.getPolyModulations(),
                           keyboard_state_);
  gui_->setOutputMemory(output_memory_.get());
  addAndMakeVisible(gui_);
  setSize(WIDTH, HEIGHT);

  grabKeyboardFocus();
  setWantsKeyboardFocus(true);
  addKeyListener(computer_keyboard_);
  postMessage(new Message());
  setOpaque(true);
}
ResourceItem::ResourceItem( KCal::ResourceCalendar *resource,
                            const QString &sub, const QString &label,
                            ResourceView *view, ResourceItem *parent )

  : QTreeWidgetItem( parent ), mResource( resource ),
    mView( view ), mBlockStateChange( false ), mIsSubresource( true ),
    mSubItemsCreated( false ), mIsStandardResource( false ), mActive( false ),
    mIsReloading( false )
{
  setFlags( flags() | Qt::ItemIsUserCheckable );
  setText( 0, label );
  mResourceColor = KOPrefs::instance()->resourceColor( sub );
  mResourceIdentifier = sub;
  setGuiState();

  treeWidget()->setRootIsDecorated( true );
}
ResourceItem::ResourceItem( ResourceCalendar *resource, ResourceView *view,
                            QTreeWidget *parent )
  : QTreeWidgetItem( parent ),
    mResource( resource ), mView( view ), mBlockStateChange( false ),
    mIsSubresource( false ), mResourceIdentifier( QString() ),
    mSubItemsCreated( false ), mIsStandardResource( false ),
    mIsReloading( false )
{
  setFlags( flags() | Qt::ItemIsUserCheckable );

  setText( 0, resource->resourceName() );
  mResourceColor = KOPrefs::instance()->resourceColor( resource->identifier() );
  setGuiState();

  if ( mResource->isActive() ) {
    createSubresourceItems();
  }
}
void ResourceItem::update()
{
  setGuiState();
}