Home AMX User Forum AMX General Discussion

What's wrong with this code?

button_event[dvTP, 3]
{
  push:
  {
    if(audioSwStatus.isMuted[cnKitchen]) 
    {
      off[vdvAudioOutputs[cnKitchen], cnMute]
    }
    else 
    {
       on[vdvAudioOutputs[cnKitchen], cnMute]
    } 
  }
}

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    The only thing that strikes me as odd is in the if statement. Try this:
    button_event[dvTP, 3]
    {
      push:
      {
        if(audioSwStatus[cnKitchen].isMuted) 
        {
          off[vdvAudioOutputs[cnKitchen], cnMute]
        }
        else 
        {
           on[vdvAudioOutputs[cnKitchen], cnMute]
        } 
      }
    }
    

    If that doesn't do it, can you post the variable declarations as well?

    Jeff
  • ericmedleyericmedley Posts: 4,177
    Are you getting a compile error? Or, is it giving you run-time errors?

    If the latter then you might be getting an array error in that cnKitchen is equal to zero when you push the button.

    You could add a condition in the IF statement to catch it.
  • a_riot42a_riot42 Posts: 1,624
    ericmedley wrote:
    Are you getting a compile error? Or, is it giving you run-time errors?

    If the latter then you might be getting an array error in that cnKitchen is equal to zero when you push the button.

    You could add a condition in the IF statement to catch it.

    It was a trick question :) It compiles and runs fine. But it seems to me that it would be easier and less bug prone to just do this:
    button_event[dvTP, 3]
    {
      push:
      {
        [vdvAudioOutputs[cnKitchen], cnMute] = ! [vdvAudioOutputs[cnKitchen], cnMute]
      }
    }
    

    Won't they accomplish the same thing? I have seen others write it the first way and I am not grokking why.
  • Spire_JeffSpire_Jeff Posts: 1,917
    a_riot42 wrote:
    It was a trick question :) It compiles and runs fine. But it seems to me that it would be easier and less bug prone to just do this:
    button_event[dvTP, 3]
    {
      push:
      {
        [vdvAudioOutputs[cnKitchen], cnMute] = ! [vdvAudioOutputs[cnKitchen], cnMute]
      }
    }
    

    Won't they accomplish the same thing? I have seen others write it the first way and I am not grokking why.

    That code will not do the same thing as the original code because the original code is using the actual mute state to set the channel feedback, where this code is just simply toggling the feedback based on the feedbacks current state. That said, you could do this:
    button_event[dvTP, 3]
    {
      push:
      {
        [vdvAudioOutputs[cnKitchen], cnMute] = !audioSwStatus.isMuted[cnKitchen]
      }
    }
    

    Jeff
  • a_riot42a_riot42 Posts: 1,624
    Spire_Jeff wrote:
    That code will not do the same thing as the original code because the original code is using the actual mute state to set the channel feedback, where this code is just simply toggling the feedback based on the feedbacks current state.

    Still not grokking. The feedback is determined by the actual mute state of the virtual. The audioSwStatus[cnKitchen].isMuted variable will get updated by the module depending on whether the mute is on or not. So when you do this:
    [vdvAudioOutputs[cnKitchen], cnMute] = ! [vdvAudioOutputs[cnKitchen], cnMute]
    

    that tells the virtual device to toggle the mute state doesn't it? The feedback will get taken care of automagically.
    Paul
  • Spire_JeffSpire_Jeff Posts: 1,917
    Yes, you are correct. That what I get for trying to help here while working on my finances :). I was thinking that you were dealing with a touchpanel, not the virtual device. My apologies.

    Jeff
  • a_riot42a_riot42 Posts: 1,624
    Spire_Jeff wrote:
    Yes, you are correct. That what I get for trying to help here while working on my finances :). I was thinking that you were dealing with a touchpanel, not the virtual device. My apologies.

    Jeff

    Yes I should have been more clear as to what these things were. It's an autopatch switch so I have an array of virtual outputs. The audioSwStatus is just a structure to store volume/mute etc. I don't really need one for mute since I can tell if an output is muted this way, if([vdvAudioOutputs[cnKitchen], cnMute]) but I haven't found a way to determine the level of a virtual level, only if its channel is on or off. Is there a way to do that? I would think there should be, other than keeping a record of it and constantly updating it.
    Paul
  • HedbergHedberg Posts: 671
    Won't they accomplish the same thing? I have seen others write it the first way and I am not grokking why.

    'Cause we get paid by the line.
  • DHawthorneDHawthorne Posts: 4,584
    I would use the second example, but I wouldn't put it on the PUSH event handler. I always break feedback out into a separate section of code, generally as it's own function or CALL. It's much, much easier to keep track of things if all similar operations are in the same place. I find this especially true of feedback - if it's all in one spot, it's easier to see if you mistakenly have two conditions on the same channel, and stuff like that.
  • a_riot42a_riot42 Posts: 1,624
    The example in the push event handler does the muting of the device and feedback is taken care of elsewhere, like you mention. I don't do any feedback in mainline as I believe AMX teaches programmers to do. I generally never have any program code running and I have found that since doing things this way the system has a snappier response time.
    Paul
Sign In or Register to comment.